Skip to content Skip to sidebar Skip to footer

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

When I run my Django Web application with Apache2.4.41 + Python 3.8.1 + Django 3.0.2 + MySQL 8.0.19 on Windows 10 Professional version it throws Value Error at /. set_wakeup_fd onl

Solution 1:

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())

Solution 2:

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's manager.py:
# top of the fileimport sys, asyncio

if sys.platform == "win32"and (3, 8, 0) <= sys.version_info < (3, 9, 0):
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Solution 3:

upgraded to python 3.8.2 , worked fine on my windows server.

release notes https://docs.python.org/release/3.8.2/whatsnew/changelog.html#python-3-8-2-final

issue bpo-34679: fixed asynci.ProactorEventLoop.close() now only calls signal.set_wakeup_fd() in the main thread.

Solution 4:

I had to downgrade to Python 3.7 and then it started to work perfectly.

Post a Comment for "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"