# Starting the daphne service, the main thread is locked.

**URL:** <https://forum.djangoproject.com/t/starting-the-daphne-service-the-main-thread-is-locked/38727>\
**Category:** Async/Channels\
**Created:** [February 10, 2025, 11:08am UTC](https://forum.djangoproject.com/t/starting-the-daphne-service-the-main-thread-is-locked/38727 "2025-02-10T11:08:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luxiaoyong](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luxiaoyong/32/24592_2.png) [@luxiaoyong](https://forum.djangoproject.com/u/luxiaoyong)\
**Post date:** [February 10, 2025, 11:08am UTC](https://forum.djangoproject.com/t/starting-the-daphne-service-the-main-thread-is-locked/38727/1 "2025-02-10T11:08:59Z")

</div>

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.

```auto
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?
