aio-libs / aiohttp-devtools

dev tools for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No graceful shutdown when CTRL-C

cecton opened this issue · comments

  • devtools: ==0.13.1
  • adiohttp: ==3.6.2
  • python: 3.8.3
  • platform: Linux x86_64

Issue Summary

There seems to be no craceful shutdown when I hit CTRL-C while running with adev runserver.

I compared with and without the dev server. My on_cleanup functions work in aiohttp but it fails with the dev server.

I noticed that one is actually triggered but it doesn't run until completion. It looks like the thread is killed.

Steps to reproduce

I suppose it is easy to reproduce with a cleanup function that waits for sometime.

I think this is one of the bugs I've already fixed, so please try v1.0. Reopen if still an issue for you.

Just encountered this on latest version 1.0.post0 - cleanup handlers do not run when running with adev runserver.

❯ dotenv run -- python -m projectname.app --port 8180
[12:45:14] DEBUG    Initialising asyncio global exception handler
           DEBUG    Initialising redis extension 
           DEBUG    Initialising websockets
======== Running on http://0.0.0.0:8180 ========
(Press CTRL+C to quit)
^C[12:45:15] DEBUG  Cleaning up websockets...
           DEBUG    Cleaning up redis extension...

Aborted!
❯ dotenv run -- adev runserver --port 8180 ./projectname

[12:45:39] Starting aux server at http://localhost:8181 ◆
[12:45:39] Starting dev server at http://localhost:8180 ●
======== Running on http://0.0.0.0:8181 ========
(Press CTRL+C to quit)
[12:45:40] DEBUG    Initialising asyncio global exception handler
           DEBUG    Initialising redis extension
           DEBUG    Initialising websockets
^C
Aborted!

Curiously the "Running on" shows before the initialisation with adev runserver, but after with just Python.

Versions:

❯ p show aiohttp-devtools
name         : aiohttp-devtools
version      : 1.0.post0
description  : Dev tools for aiohttp

dependencies
 - aiohttp >=3.8.0
 - click >=6.6
 - devtools >=0.5
 - Pygments >=2.2.0
 - watchgod >=0.2
 - 
❯ p show aiohttp
name         : aiohttp
version      : 3.8.1
description  : Async http client/server framework (asyncio)

dependencies
 - aiosignal >=1.1.2
 - async-timeout >=4.0.0a3,<5.0
 - attrs >=17.3.0
 - charset-normalizer >=2.0,<3.0
 - frozenlist >=1.1.1
 - multidict >=4.5,<7.0
 - yarl >=1.0,<2.0

EDIT: Upon further investigation I've found that ctrl+c is not working consistently running directly with just aiohttp, it seems to always clean up if I press ctrl+c within seconds of starting the server, but doing it after 20+30 seconds with some request having been made it's like 50/50 if it works. The devtools seems to consistently not work for me, but that might be related to whatever is causing the flakyness without the dev tools.

Pretty sure your problem is dotenv. It runs the app in a subprocess, so your Ctrl+C is telling dotenv to quit, which will then just kill the subprocess at the same time.