Python 3.11 + Django 4.2.17 + asgiref 3.8.1 + daphne 4.1.2
Command:
daphne health_inspect.asgi:application --bind 127.0.0.1 --port 8002 --application_close_timeout 10
Using Daphne as the server, run the following command to start the service:
daphne -t 30 --application_close_timeout 10 health_inspect.asgi:application --bind 127.0.0.1 --port 8002
.
When making API calls, the message “took too long to shut down and was killed” appears, executing async_to_sync
afterward will cause the service to hang.
By reading the source code, it was found that the execution of the function daphne.server.Server.application_checker
is the direct cause of the main thread being locked.
mport asyncio
from asgiref.sync import async_to_sync
async def wait():
await asyncio.sleep(1)
def get_publickey(request):
time.sleep(50)
async_to_sync(wait)()
return HttpResponse(json.dumps({}))
The above is an example of the interface code. May I ask, is it due to the way I use Daphne, or is it a bug in Daphne?