Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How django handles simultaneous requests with concurrency over global variables?

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.

like image 373
Babu Avatar asked Nov 01 '12 06:11

Babu


1 Answers

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 and post_save. I'd recommend putting some more thought into your design.

like image 180
Jamey Sharp Avatar answered Oct 23 '22 17:10

Jamey Sharp