We’re rolling out our first django application under mod_wsgi as
`WSGIDaemonProcess our-appname processes=6 threads=15'`
and we’re having a discussion about whether our Python code and the Redis and Postgres libraries it uses needs to be thread-safe or not.
From what I can tell from reading the mod_wsgi documentation, even though the apache worker is processing requests with multiple apache threads, our python code is for all intents and purposes single-threaded. I don’t see any warnings on the mod_wsgi docs saying “Beware!! You now have to worry about Global Data and Thread Safety!” but there’s also no explicit “Don’t Worry About Threads There Aren’t Any”.
We’re not doing anything explicitly with threads in our python code, there is no mention of them in anything we’ve written.
But some people here are of the opinion that since we’re running with threads=15 that we are now in in the multi-threaded world.
Can anyone clarify what’s actually going on here? Is our Python code now subject to multiple threads of execution through the same data where it wasn’t before, or not?
Yes obviously you are running multi-threaded app and it will create problems if you don’t take care with globals, Class attributes etc
If you need to keep something globally, keep it in thread local storage.
Here is a quote from modwsgi doc, Building_A_Portable_Application
So I think you have been sufficiently warned.