nvdv / vprof

Visual profiler for Python
BSD 2-Clause "Simplified" License
3.95k stars 154 forks source link

[Help] How to test twisted code #109

Open whg517 opened 3 years ago

whg517 commented 3 years ago
Description

I have sample example, when i run, but an error occurred.

from twisted.internet import reactor, task
from vprof import runner

def ppp():
    print('called')

def profile():
    reactor.callLater(3, reactor.stop)
    t = task.LoopingCall(ppp)
    t.start(0.5)
    reactor.run()

if __name__ == '__main__':
    runner.run(profile, 'cmhp')
Traceback (most recent call last):
  File "/home/kevin/workspaces/develop/python/crawlerstack/crawlerstack_proxypool/demo.py", line 19, in <module>
    runner.run(profile, 'cmhp')
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/vprof/runner.py", line 91, in run
    run_stats = run_profilers((func, args, kwargs), options)
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/vprof/runner.py", line 73, in run_profilers
    run_stats[option] = curr_profiler.run()
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/vprof/base_profiler.py", line 172, in run
    return self.profile()
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/vprof/flame_graph.py", line 172, in profile_function
    result = self._run_object(*self._run_args, **self._run_kwargs)
  File "/home/kevin/workspaces/develop/python/crawlerstack/crawlerstack_proxypool/demo.py", line 15, in profile
    reactor.run()
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/twisted/internet/base.py", line 1282, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/twisted/internet/base.py", line 1262, in startRunning
    ReactorBase.startRunning(self)
  File "/home/kevin/.virtualenvs/crawlerstack_proxypool-VZQM9sgQ/lib/python3.7/site-packages/twisted/internet/base.py", line 765, in startRunning
    raise error.ReactorNotRestartable()
twisted.internet.error.ReactorNotRestartable
Version and platform