ValueError: set_wakeup_fd only works in main thread on Windows on Python 3.8 with Django 3.0.2 or Flask 2.0.0
I have exactly the same bug. I opened the issue.
If you want to stay on the current Python version I have found the temporal solution which is to add following lines to asgiref\__init__.py
(as it was suggested in issue):
if sys.platform == "win32" and sys.version_info >= (3, 8, 0): asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Not only Django, but you will also meet this error with Flask since Flask 2.0.0 uses asgiref to support async
.
This bug was fixed in Python 3.9, so there are two solutions:
- Upgrade to Python 3.9
- Add the temp fix as follows (based on Dennis B's answer) to your entry script, for example, Flask's
app.py
or Django'smanager.py
:
# top of the fileimport sys, asyncioif sys.platform == "win32" and (3, 8, 0) <= sys.version_info < (3, 9, 0): asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
I had to downgrade to Python 3.7 and then it started to work perfectly.