Crash because asgiref 3.3.2 makes sure async_to_sync and sync_to_async get passed an awaitable
See original GitHub issueThis is how I think the error happens:
create_application
inserver.py
is called.- This lambda is created
send=lambda message: self.handle_reply(protocol, message)
- At some point, this lambda is passed into
async_to_sync
- 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:
- Stack Overflow
- The Django Users mailing list django-users@googlegroups.com (https://groups.google.com/forum/#!forum/django-users)
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:
- Created 2 years ago
- Comments:8 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
See #364 for fix.
You’ll need asgiref 3.3.3 which added the partial support: https://github.com/django/asgiref/blob/main/CHANGELOG.txt