Skip to content

WindowsSelectorEventLoopPolicy doesn't raise KeyboardInterrupt immediately #101166

Closed as duplicate of#77373
@davetapley

Description

@davetapley

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.

import asyncio
import sys

if sys.platform == 'win32':
   asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def sleep():
    print('sleeping')
    await asyncio.sleep(10)
    print('done')

try:
    asyncio.run(sleep())
except KeyboardInterrupt:
    print('interrupted')

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions