I have a django instance hosted via apache/mod_wsgi. I use pre_save
and post_save
signals to store the values before and after save for later comparisons. For that I use global variables to store the pre_save
values which can be accessed in the post_save
signal handler.
My question is, if two requests A and B come together simultaneously requesting a same web service, will it be concurrent? The B should not read the global variable which is written by A and vice versa.
PS: I don't use any threading Lock
on variables.
This partly depends on your
mod_wsgi
configuration. If you configure it to use only one thread per process, then global variables are safe--although I wouldn't recommend using them, for a variety of reasons. In a multi-thread configuration, there is nothing guaranteeing that requests won't get mixed up if you use global variables.You should be able to find some more local place to stash the data you need between
pre_save
andpost_save
. I'd recommend putting some more thought into your design.