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
For context: I need WindowsSelectorEventLoopPolicy to mitigate this error with pyzmq:
RuntimeError: Proactor event loop does not implement add_reader family of methods required for zmq. zmq will work
with proactor if tornado >= 6.1 can be found. Use `asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())` or install 'tornado>=6.1' to avoid this error.
Your environment
CPython versions tested on: 3.9.10
Operating system and architecture: Windows 10, 64-bit
The text was updated successfully, but these errors were encountered:
The main thread is blocked in a Winsock select() call. Since the interpreter calls signal handlers on the main thread, the runner's SIGINT handler (i.e. asyncio.runners.Runner._on_sigint()) won't be called until the interpreter resumes executing on the main thread.
You can complete the select() call using the event loop's _write_to_self() method, which is allowed to be called from another thread. A native Windows console control handler is always called on a new thread. For example:
importasyncioimportsysifsys.platform=='win32':
importctypesimportsignalasyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
runner=None@ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)defctrl_handler(event):
ifevent==signal.CTRL_C_EVENT:
ifrunnerisnotNone:
loop=runner.get_loop()
ifloopisnotNone:
loop._write_to_self()
# Chain to the next registered control handler, which is probably # the C runtime library's SIGINT/SIGBREAK implementation.returnFalsekernel32=ctypes.WinDLL('kernel32', use_last_error=True)
kernel32.SetConsoleCtrlHandler(ctrl_handler, True)
asyncdefsleep():
print('sleeping')
awaitasyncio.sleep(10)
print('done')
try:
withasyncio.Runner() asrunner:
runner.run(sleep())
exceptKeyboardInterrupt:
print('interrupted')
Bug report
Run the snippet below and Ctrl+C,
observe
interrupted
will only be printed after ten seconds.Comment out
set_event_loop_policy
and repeat,observe
interrupted
is printed immediately.For context: I need
WindowsSelectorEventLoopPolicy
to mitigate this error withpyzmq
:Your environment
The text was updated successfully, but these errors were encountered: