This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: set_wakeup_fd() only works in main thread
Type: crash Stage: resolved
Components: asyncio Versions: Python 3.9
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: MeneMeneTekel, asvetlov, gvanrossum, yselivanov
Priority: normal Keywords:

Created on 2021-01-23 10:40 by MeneMeneTekel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg385528 - (view) Author: (MeneMeneTekel) Date: 2021-01-23 10:40
This problem is marked as solved in issue38563, BUT the solution refers to some signal issues being solved - I'm using Python 3.8.7 on windows 10, where a signal solution may not work. I.e. my django (vers. 3.1.5) website crashes every second call with the message:

  File "C:\Winpython\WPy64-3870\python-3.8.7.amd64\lib\asyncio\proactor_events.py", line 632, in __init__
    signal.set_wakeup_fd(self._csock.fileno())
ValueError: set_wakeup_fd only works in main thread
msg395084 - (view) Author: (MeneMeneTekel) Date: 2021-06-04 13:51
Update: I just tried it again with 
 - Windows 10 Pro, 21H1
 - WinPython 3.9.4
 - Apache24
 - Django 3.2.4
 - mod_wsgi-4.8.0-cp39-cp39-win_amd64

Actually, there is no change, it got even worse. i.e. this wake up situation occurs more often. 

Remember: Changing WinPython 3.9.4 to WinPython 3.7.7 with mod_wsgi-4.7.1-cp37-cp37m-win_amd64 and all works fine!

Perhaps it's useful to have a stack trace? Here we are:

******
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819] mod_wsgi (pid=6556): Failed to exec Python script file 'C:/.../.../.../wsgi.py'.
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819] mod_wsgi (pid=6556): Exception occurred processing WSGI script 'C:/.../.../.../wsgi.py'.
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819] Traceback (most recent call last):\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:/.../.../.../wsgi.py", line 19, in <module>\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     application = get_wsgi_application()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     return WSGIHandler()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 127, in __init__\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     self.load_middleware()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\core\\handlers\\base.py", line 58, in load_middleware\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     mw_instance = middleware(adapted_handler)\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Users\\mail\\OneDrive\\Dokumente\\Privat\\Python\\Django\\Applications\\groupregister\\middleware\\sessions.py", line 54, in __init__\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     self.user_reg = get_user_model().objects \\\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\db\\models\\query.py", line 399, in aggregate\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     return query.get_aggregation(self.db, kwargs)\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\db\\models\\sql\\query.py", line 502, in get_aggregation\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     result = compiler.execute_sql(SINGLE)\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py", line 1173, in execute_sql\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     cursor = self.connection.cursor()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\site-packages\\django\\utils\\asyncio.py", line 19, in inner\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     event_loop = asyncio.get_event_loop()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\asyncio\\events.py", line 639, in get_event_loop\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     self.set_event_loop(self.new_event_loop())\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\asyncio\\events.py", line 659, in new_event_loop\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     return self._loop_factory()\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\asyncio\\windows_events.py", line 310, in __init__\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     super().__init__(proactor)\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]   File "C:\\Winpython\\WPy64-3940\\python-3.9.4.amd64\\lib\\asyncio\\proactor_events.py", line 632, in __init__\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819]     signal.set_wakeup_fd(self._csock.fileno())\r
[Fri Jun 04 15:31:37.428939 2021] [wsgi:error] [pid 6556:tid 1140] [client 111.222.333.444:50819] ValueError: set_wakeup_fd only works in main thread of the main interpreter\r
******

Would be nice to be able to switch zu Python 3.9.4 ff. soon...

Many thanks,
MeneMeneTekel
msg406679 - (view) Author: (MeneMeneTekel) Date: 2021-11-20 18:01
Finally... it works for me - I migrated to

 - Windows Server 2019 Datacenter
 - WinPython 3.9.5
 - Apache24 AH
 - Django 3.2.9
 - mod_wsgi-4.9.0-cp39-cp39-win_amd64

Whoever made that it works again.... thanks a lot ;-)

MeneMeneTekel
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87173
2021-11-20 18:01:02MeneMeneTekelsetstatus: open -> closed
resolution: works for me
messages: + msg406679

stage: resolved
2021-06-04 13:51:09MeneMeneTekelsetnosy: gvanrossum, asvetlov, yselivanov, MeneMeneTekel
messages: + msg395084
versions: + Python 3.9, - Python 3.8
2021-01-24 01:38:13gvanrossumsetnosy: + gvanrossum
2021-01-23 10:40:30MeneMeneTekelcreate