Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: no running event loop #378

Closed
variable opened this issue Aug 31, 2021 · 2 comments
Closed

RuntimeError: no running event loop #378

variable opened this issue Aug 31, 2021 · 2 comments

Comments

@variable
Copy link

variable commented Aug 31, 2021

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

@carltongibson
Copy link
Member

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

@variable
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants