Home » Python » ValueError: set_wakeup_fd only works in main thread on Apache2.4.41 + Python 3.8.1 + Django 3.0.2 + MySQL 8.0.19-Exceptionshub

ValueError: set_wakeup_fd only works in main thread on Apache2.4.41 + Python 3.8.1 + Django 3.0.2 + MySQL 8.0.19-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

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 only works in main thread.

This issue was a result of regression in Python 3.8 and was fixed in November in later builds of Python. For more details – https://bugs.python.org/issue38563.

Stacktrace of the error is as follows –

Environment:

Request Method: GET
Request URL: http://127.0.0.1/

Django Version: 3.0.2
Python Version: 3.8.1
Installed Applications:
['Analysis.apps.AnalysisConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize']


Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "c:\python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "c:\python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "c:\python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\IndianMarketAnalysis\ISMA\Analysis\views.py", line 8, in home
    date_list = dict(d.date_list())
  File "F:\IndianMarketAnalysis\ISMA\Analysis\models.py", line 7, in date_list
    with connection.cursor() as cursor:
  File "c:\python38\lib\site-packages\django\utils\asyncio.py", line 19, in inner
    event_loop = asyncio.get_event_loop()
  File "c:\python38\lib\asyncio\events.py", line 636, in get_event_loop
    self.set_event_loop(self.new_event_loop())
  File "c:\python38\lib\asyncio\events.py", line 656, in new_event_loop
    return self._loop_factory()
  File "c:\python38\lib\asyncio\windows_events.py", line 310, in __init__
    super().__init__(proactor)
  File "c:\python38\lib\asyncio\proactor_events.py", line 632, in __init__
    signal.set_wakeup_fd(self._csock.fileno())

Exception Type: ValueError at /
Exception Value: set_wakeup_fd only works in main thread

Further, this application works very well on local Development Environment using – python manage.py runserver.

Please suggest the next steps to move forward.

How to&Answers:

I have exactly the same bug. I opened the issue.