Cleanup On Process Shutdown in mod_wsgi 3?

12 views
Skip to first unread message

Eric Lemings

unread,
Aug 29, 2019, 6:03:06 PM8/29/19
to modwsgi
Greetings all,

The current mod_wsgi documentation <https://modwsgi.readthedocs.io/en/develop/user-guides/registering-cleanup-code.html> states in the "Cleanup On Process Shutdown" section that a function registered via the atexit module will be called during a "graceful" shutdown.  I've tried this in mod_wsgi 3.x and it doesn't seem to work.  Does this only apply to mod_wsgi 4.x and if so, can the same intent be satisfied somehow in mod_wsgi 3.x?

Thanks,
Eric.

P.S. Why am I using mod_wsgi 3.x?  It's the default version that ships with RHEL 7.

Graham Dumpleton

unread,
Aug 29, 2019, 6:09:10 PM8/29/19
to mod...@googlegroups.com


> On 30 Aug 2019, at 6:57 am, Eric Lemings <eric.l...@gmail.com> wrote:
>
> Greetings all,
>
> The current mod_wsgi documentation <https://modwsgi.readthedocs.io/en/develop/user-guides/registering-cleanup-code.html> states in the "Cleanup On Process Shutdown" section that a function registered via the atexit module will be called during a "graceful" shutdown. I've tried this in mod_wsgi 3.x and it doesn't seem to work. Does this only apply to mod_wsgi 4.x and if so, can the same intent be satisfied somehow in mod_wsgi 3.x?

In principal it should work in mod_wsgi 3.X.

With any atexit handler, it can appear not to work if your program is creating background threads and they were not created as daemon threads. They can block process shutdown if nothing makes them stop. This is because any non daemon threads are waited upon first, before atexit callbacks are invoked.

In this scenario, the shutdown timeout will expire and the process forcibly shutdown.

You should enable LogLevel of info (if using err or warn) in Apache config. When that is done, mod_wsgi should output log messages about shutdown and whether the process had to be forcibly shutdown.

> P.S. Why am I using mod_wsgi 3.x? It's the default version that ships with RHEL 7.

What version of RHEL 7 are you using? RHEL has mod_wsgi 4.5.? at least.

Graham

Reply all
Reply to author
Forward
0 new messages