django / daphne

Django Channels HTTP/WebSocket server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: no running event loop

variable opened this issue · comments

When I run systemctl start daphne I get the following error

Traceback (most recent call last):
  File "/srv/www/portal/bin/daphne", line 8, in <module>
    sys.exit(CommandLineInterface.entrypoint()) 
  File "/srv/www/portal/lib/python3.8/site-packages/daphne/cli.py", line 170, in entrypoint
    cls().run(sys.argv[1:])
  File "/srv/www/portal/lib/python3.8/site-packages/daphne/cli.py", line 232, in run
    application = import_by_path(args.application)
  File "/srv/www/portal/lib/python3.8/site-packages/daphne/utils.py", line 12, in import_by_path
    target = importlib.import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/srv/www/portal/portal/./portal/asgi.py", line 3, in <module>
    from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter
  File "/srv/www/portal/lib/python3.8/site-packages/channels/routing.py", line 10, in <module>
    from channels.http import AsgiHandler
  File "/srv/www/portal/lib/python3.8/site-packages/channels/http.py", line 9, in <module>
    from asgiref.sync import async_to_sync, sync_to_async
  File "/srv/www/portal/lib/python3.8/site-packages/asgiref/sync.py", line 304, in <module>
    class SyncToAsync:
  File "/srv/www/portal/lib/python3.8/site-packages/asgiref/sync.py", line 328, in SyncToAsync
    loop = get_running_loop()
RuntimeError: no running event loop

The service definition:

[Unit]
Description=daphne service
PartOf=postgresql.service
After=postgresql.service

[Service]
WorkingDirectory=/srv/www/portal/portal/
Environment=JSON_SETTINGS=/srv/www/portal/settings.json
Environment=ASGI_THREADS=10
ExecStart=/srv/www/portal/bin/daphne -b 0.0.0.0 -p 8000 portal.asgi:application
Restart=always
KillSignal=SIGTERM
NotifyAccess=all

[Install]
WantedBy=multi-user.target

This is my asgi.py

import os
import django
from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portal.settings")
django.setup()

from api.routing import websocket_urlpatterns
from channels.auth import AuthMiddlewareStack
from api.consumers import MultiplexConsumer


application = ProtocolTypeRouter({
  "http": AsgiHandler(),
  "websocket": AuthMiddlewareStack(
        URLRouter(
            websocket_urlpatterns
        )
    ),
})

I am have the following versions on python 3.8

Django==2.2.24
channels==3.0.4
daphne==3.0.2
asgiref==3.4.1

related SO https://stackoverflow.com/questions/68993061/daphne-channel-v3-deployment-runtimeerror-no-running-event-loop

Duplicate of django/asgiref#292 — caused by the presence on the ASGI_THREADS environment variable. Should be fixed in the next ASGIRef release.

Duplicate of django/asgiref#292 — caused by the presence on the ASGI_THREADS environment variable. Should be fixed in the next ASGIRef release.

thanks for the quick reply, any idea how long before the next release?