django multiprocess problem
Posted
by iKiR
on Stack Overflow
See other posts from Stack Overflow
or by iKiR
Published on 2010-05-26T18:16:54Z
Indexed on
2010/05/26
18:21 UTC
Read the original article
Hit count: 209
I have django application, running under lighttpd via fastcgi. FCGI running script looks like:
python manage.py runfcgi socket=<path>/main.socket
method=prefork \
pidfile=<path>/server.pid \
minspare=5 maxspare=10 maxchildren=10 maxrequests=500 \
I use SQLite. So I have 10 proccess, which all work with the same DB. Next I have 2 views:
def view1(request)
...
obj = MyModel.objects.get_or_create(id=1)
obj.param1 = <some value>
obj.save ()
def view2(request)
...
obj = MyModel.objects.get_or_create(id=1)
obj.param2 = <some value>
obj.save ()
And If this views are executed in two different threads sometimes I get MyModel instance in DB with id=1 and updated either param1 or param2 (BUT not both) - it depends on which process was the first. (of course in real life id changes, but sometimes 2 processes execute these two views with same id)
The question is: What should I do to get instance with updated param1 and param2? I need something for merging changes in different processes.
One decision is create interprocess lock object but in this case I will get sequence executing views and they will not be able to be executed simultaneously, so I ask help
© Stack Overflow or respective owner