ymichael / cprofilev

:fire: An easier way to use cProfile
https://pypi.python.org/pypi/CProfileV
MIT License
418 stars 30 forks source link

How to use with asyncio? #30

Open hemulin opened 4 years ago

hemulin commented 4 years ago

Hi and thanks for this lovely project.

I have a small webserver using aiohttp (which in turn, wraps asyncio).

When running it like so: python -m cprofilev main.py I get the following error:

[cProfileV]: cProfile output available at http://127.0.0.1:4000
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/cProfile.py", line 100, in runctx
    exec(cmd, globals, locals)
  File "main.py", line 255, in <module>
    main()
  File "main.py", line 239, in main
    web.run_app(app, port=WEBSERVER_PORT)
  File "/home/hemulin/workspace/venv/lib/python3.8/site-packages/aiohttp/web.py", line 409, in run_app
    loop = asyncio.get_event_loop()
  File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1'.

Any idea how to use this profiler with asyncio?