vprof icon indicating copy to clipboard operation
vprof copied to clipboard

[Help] How to test twisted code

Open whg517 opened this issue 5 years ago • 0 comments

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
  • vprof 0.38
  • Linux 5.4.70-amd64-desktop #1 SMP Wed Oct 14 15:24:23 CST 2020 x86_64 GNU/Linux
  • Python 3.7.3
  • twisted 20.3.0

whg517 avatar Jan 08 '21 03:01 whg517