-
Notifications
You must be signed in to change notification settings - Fork 691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError at startup in Python 3.7.1+ when using --py-call-osafterfork
option and logging module
#1978
Comments
@joshuahlang Don't know if --py-call-osafterfork should default to true but if one uses it we should probably call the other python functions as you noted. Reproduced with python 3.7.2 |
I suggested it be the default because the fix for an issue in Python's |
Note that the fix for this new CPython bug (python/cpython#11908) makes half of the error go away. It is now:
Repeated once for every worker uWSGI spins up. What are the consequences of disabling Is there any Python code that I can locally put in place as a work-around to get this working? |
Interesting: Based on my reading of the documentation for |
@nickwilliams-eventbrite yeah the python PR is kinda unrelated to the uwsgi issue. Agree with your analysis but am not sure I'll have time in the foreseeable future to take a look at this myself though. |
@xrmx: Thanks for the quick reply. Given your inability to address it quickly and the fact that this is causing startup errors in Python 3.7 (and that those errors indicate incorrect behavior), I have put together a pull request (#1995) that addresses this issue and that I hope will meet your requirements. I tried to keep it as simple as possible, but unfortunately it required adding another plugin function, as there was simply no other post-fork plugin function run on the master (only on the children). I learned something interesting along the way. Other than changing the log output, it appears |
[bump] Could I get some 👀 on that above pull request, please? Thanks! |
This commit works around a requirement introduced in Python 3.7 that all calls to fork() be preceeded by calls to PyOS_BeforeFork() in the parent and PyOS_AfterFork_Parent() and PyOS_AfterFork_Child() in the respective processes. Also, Python 3.7 always initialize threads, but if the option is not set on uWSGI the thread-local data is not set and it causes random crashes, therefore it is now a fatal error if that option is not set. A plethora of new hooks were added because Python specifies that after fork the first calls must be to PyOS_AfterFork_* and unfortunately uWSGI was doing a bunch of stuff before calling the existing post_fork() hook. We decided to modify the function uwsgi_fork() itself because it would make it easier to handle all use-cases: mules, spoolers, re-forking of workers, lazy apps, etc. Reference: https://docs.python.org/3.7/c-api/sys.html#c.PyOS_BeforeFork https://docs.python.org/3.7/c-api/init.html#c.PyEval_InitThreads unbit#1995 unbit#1978 https://github.com/awelzel/uwsgi/tree/before-after-fork
Remove the py-call-osafterfork setting from uwsgi.ini. This is about to be deprecated, and is buggy with Python 3.7. References: - mitodl/micromasters#4569 - unbit/uwsgi#1978 - unbit/uwsgi#1995
Remove the py-call-osafterfork setting from uwsgi.ini. This is about to be deprecated, and is buggy with Python 3.7. References: - mitodl/micromasters#4569 - unbit/uwsgi#1978 - unbit/uwsgi#1995
Still an issue in Python 3.8 |
Prevents runtime error in logging module under Python 3.7.1+ (see unbit/uwsgi#1978)
This commit works around a requirement introduced in Python 3.7 that all calls to fork() be preceeded by calls to PyOS_BeforeFork() in the parent and PyOS_AfterFork_Parent() and PyOS_AfterFork_Child() in the respective processes. Also, Python 3.7 always initialize threads, but if the option is not set on uWSGI the thread-local data is not set and it causes random crashes, therefore it is now a fatal error if that option is not set. A plethora of new hooks were added because Python specifies that after fork the first calls must be to PyOS_AfterFork_* and unfortunately uWSGI was doing a bunch of stuff before calling the existing post_fork() hook. We decided to modify the function uwsgi_fork() itself because it would make it easier to handle all use-cases: mules, spoolers, re-forking of workers, lazy apps, etc. Reference: https://docs.python.org/3.7/c-api/sys.html#c.PyOS_BeforeFork https://docs.python.org/3.7/c-api/init.html#c.PyEval_InitThreads unbit#1995 unbit#1978 https://github.com/awelzel/uwsgi/tree/before-after-fork
Issue is still existing three years later, can we move forward with the PR mentioned above? |
It appears that the fix for this issue, which was released in CPython 3.7.1, introduced this error. This change relies on
PyOS_BeforeFork()
,PyOS_AfterFork_Parent()
andPyOS_AfterFork_Child()
being called, butuWSGI
only callsPyOS_AfterFork_Child()
. The change in the Pythonlogging
module in 3.7.1 relies onPyOS_BeforeFork()
being called to acquire a lock in thelogging
module pre-fork, and then will release it inPyOS_AfterFork_Parent()
andPyOS_AfterFork_Child()
.Given that the Python
logging
module now relies on this behavior, one could argue thatpy-call-osafterfork = true
should be the default.Here is an example of the full error, with the necessary code to reproduce it following:
This is simple to reproduce in Docker using:
and the example application from the
uWSGI
documentation:The text was updated successfully, but these errors were encountered: