diff --git a/CHANGES/5098.bugfix b/CHANGES/5098.bugfix new file mode 100644 index 00000000000..0bd27fe7fb8 --- /dev/null +++ b/CHANGES/5098.bugfix @@ -0,0 +1,2 @@ +Make `web.run_app()` more responsive to Ctrl+C on Windows for Python < 3.8. It slightly +increases CPU load as a side effect. diff --git a/aiohttp/web.py b/aiohttp/web.py index a5de6fcee54..21522620623 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -372,8 +372,17 @@ async def _run_app(app: Union[Application, Awaitable[Application]], *, names = sorted(str(s.name) for s in runner.sites) print("======== Running on {} ========\n" "(Press CTRL+C to quit)".format(', '.join(names))) + + # sleep forever by 1 hour intervals, + # on Windows before Python 3.8 wake up every 1 second to handle + # Ctrl+C smoothly + if sys.platform == "win32" and sys.version_info < 3.8: + delay = 1 + else: + delay = 3600 + while True: - await asyncio.sleep(3600) # sleep forever by 1 hour intervals + await asyncio.sleep(delay) finally: await runner.cleanup()