Skip to content
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

Postfork Event Handler? #864

Open
xmatos-so opened this issue Nov 2, 2023 · 2 comments
Open

Postfork Event Handler? #864

xmatos-so opened this issue Nov 2, 2023 · 2 comments

Comments

@xmatos-so
Copy link

The uwsgidecorators package has a postfork decorator that can be used to run code after fork(). Does mod_wsgi have an event handler similar to that?

https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#uwsgidecorators.postfork

@GrahamDumpleton
Copy link
Owner

No, mod_wsgi doesn't have one because under mod_wsgi there is no equivalent situation whereby your application code is loaded into a parent process, with that then being forked to create the worker processes which accept requests. In mod_wsgi the Python interpreter is initialised and your application loaded fresh in each process.

Note, you should never use obsolete option WSGILazyInitialization which would result in Python being initialized in the parent process as it is a huge security risk and for many Python versions leaks memory. Even if you had enabled that obsolete option, your application is still not preloaded in the parent process so any such post fork handler is not needed.

Why do you think you the an equivalent for the uWSGI feature?

@xmatos-so
Copy link
Author

I was just wondering if there was such a thing. I'm implementing an SDK that supports two multi-process modes, one that requires an external sync service and a Redis cache, and another that can run on preforked web servers such as uWSGI or GUnicorn. I was wondering if it would be possible to use mod_wsgi for that. Thank you very much for your answer! I really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants