question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash because asgiref 3.3.2 makes sure async_to_sync and sync_to_async get passed an awaitable

See original GitHub issue

This is how I think the error happens:

  1. create_application in server.py is called.
  2. This lambda is created send=lambda message: self.handle_reply(protocol, message)
  3. At some point, this lambda is passed into async_to_sync
  4. You get an error.

The exact error is:

Traceback (most recent call last):
  File "/home/XYZ/venv/lib/python3.6/site-packages/channels/http.py", line 184, in __call__
    self.send = async_to_sync(send)
  File "/home/XYZ/venv/lib/python3.6/site-packages/asgiref/sync.py", line 105, in __init__
    raise TypeError("async_to_sync can only be applied to async functions.")
TypeError: async_to_sync can only be applied to async functions.

I have tried this with channels==3.0.0. I am on Python 3.6.8.

Issues are for concrete, actionable bugs and feature requests only - if you’re just asking for debugging help or technical support we have to direct you elsewhere. If you just have questions or support requests please use:

We have to limit this because of limited volunteer time to respond to issues!

Please also try and include, if you can:

  • Your OS and runtime environment, and browser if applicable
  • A pip freeze output showing your package versions
  • What you expected to happen vs. what actually happened
  • How you’re running Channels (runserver? daphne/runworker? Nginx/Apache in front?)
  • Console logs and full tracebacks of any errors

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
adamchainzcommented, Apr 6, 2021

See #364 for fix.

1reaction
adamchainzcommented, Apr 6, 2021

You’ll need asgiref 3.3.3 which added the partial support: https://github.com/django/asgiref/blob/main/CHANGELOG.txt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bad type hints for async_to_sync and sync_to_async #254
On asgiref 3.3.2+ mypy complains: $ mypy test.py test.py:14: error: Incompatible types in "await" (actual type "Union[Any, SyncToAsync]", ...
Read more >
asgiref - PyPI
AsyncToSync lets a synchronous subthread stop and wait while the async function is called on the main thread's event loop, and then control...
Read more >
How to use the asgiref.sync.SyncToAsync function in ... - Snyk
SyncToAsync function in asgiref. To help you get started, we've selected a few asgiref examples, based on popular ways it is used in...
Read more >
feat: created widget_group_17 django project (4a36f75f ...
Activates the Python virtual environment located in the specified location. .Example.
Read more >
Source code for asgiref.sync - Django documentation
In Python 3.7+, the ThreadSensitiveContext() context manager may be used to ... SyncToAsync.threadlocal, "main_event_loop_pid", None ) # We make sure the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found