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
When running the following program, you will get a 'RuntimeError: Cannot run the event loop while another loop is running' error. If the patch is not applied, the program will run normally.
When running the following program, you will get a 'RuntimeError: Cannot run the event loop while another loop is running' error. If the patch is not applied, the program will run normally.
import asyncio
import threading
import time
import gevent
import gevent.monkey
gevent.monkey.patch_all()
import asyncio_gevent
asyncio.set_event_loop_policy(asyncio_gevent.EventLoopPolicy())
def _start_event_loop(loop) -> None:
asyncio.set_event_loop(loop)
loop.run_forever()
loop.close()
def _get_threaded_loop():
new_loop = asyncio.new_event_loop()
thread_loop = threading.Thread(target=_start_event_loop, args=(new_loop,), daemon=True)
thread_loop.start()
return new_loop
async def test_async():
while True:
await asyncio.sleep(3)
print("test", time.time())
async def test_async2():
while True:
await asyncio.sleep(3)
print("test2", time.time())
if name == "main":
_loop = _get_threaded_loop()
asyncio.run_coroutine_threadsafe(test_async(), _loop)
asyncio.run(test_async2())
The text was updated successfully, but these errors were encountered: