You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to run an asyncio-based function inside a greenlet but I am running into an issue where the eventloop is started whilst another is already running. Here's a minimal example:
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 596, in run_forever
self._check_running()
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 590, in _check_running
raise RuntimeError(
RuntimeError: Cannot run the event loop while another loop is running
2024-01-26T10:07:42Z <Greenlet at 0x7fdd85be36a0: <bound method BaseEventLoop.run_forever of <EventLoop running=False closed=False debug=False>>> failed with RuntimeError
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 651, in run_until_complete
raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2024-01-26T10:07:42Z <Greenlet at 0x7fdd85be3560: <bound method BaseEventLoop.run_until_complete of <EventLoop running=False closed=False debug=False>>(<Task pending name='Task-2' coro=<async_main() run)> failed with RuntimeError
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/usr/local/lib/python3.11/site-packages/asyncio_gevent/future_to_greenlet.py", line 118, in _run
return ensured_future.result()
^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.InvalidStateError: Result is not set.
2024-01-26T10:07:42Z <Greenlet at 0x7fdd85be2de0: _run(future=<coroutine object async_main at 0x7fdd85d82980>, loop=None, autostart_future=True, on_cancelled=<function future_to_greenlet.<locals>.on_cancelled)> failed with InvalidStateError
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/usr/local/lib/python3.11/site-packages/asyncio_gevent/async_to_sync.py", line 37, in fn
return greenlet.get()
^^^^^^^^^^^^^^
File "src/gevent/greenlet.py", line 805, in gevent._gevent_cgreenlet.Greenlet.get
File "src/gevent/greenlet.py", line 373, in gevent._gevent_cgreenlet.Greenlet._raise_exception
File "/usr/local/lib/python3.11/site-packages/gevent/_compat.py", line 66, in reraise
raise value.with_traceback(tb)
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/usr/local/lib/python3.11/site-packages/asyncio_gevent/future_to_greenlet.py", line 118, in _run
return ensured_future.result()
^^^^^^^^^^^^^^^^^
asyncio.exceptions.InvalidStateError: Result is not set.
2024-01-26T10:07:42Z <Greenlet at 0x7fdd85be2ac0: fn> failed with InvalidStateError
sys:1: RuntimeWarning: coroutine 'async_main' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<async_main() running at /code/src/comsdk/cli/main.py:10>>
I suspect that I am using either asyncio, gevent or asyncio-gevent wrongly here.
The text was updated successfully, but these errors were encountered:
I want to run an asyncio-based function inside a greenlet but I am running into an issue where the eventloop is started whilst another is already running. Here's a minimal example:
This will fail with the following output:
I suspect that I am using either
asyncio
,gevent
orasyncio-gevent
wrongly here.The text was updated successfully, but these errors were encountered: