Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango multiprocess problem
    text
    copied!<p>I have django application, running under lighttpd via fastcgi. FCGI running script looks like:</p> <pre><code>python manage.py runfcgi socket=&lt;path&gt;/main.socket method=prefork \ pidfile=&lt;path&gt;/server.pid \ minspare=5 maxspare=10 maxchildren=10 maxrequests=500 \ </code></pre> <p>I use SQLite. So I have 10 proccess, which all work with the same DB. Next I have 2 views:</p> <pre><code>def view1(request) ... obj = MyModel.objects.get_or_create(id=1) obj.param1 = &lt;some value&gt; obj.save () def view2(request) ... obj = MyModel.objects.get_or_create(id=1) obj.param2 = &lt;some value&gt; obj.save () </code></pre> <p>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)</p> <p>The question is: What should I do to get instance with updated param1 and param2? I need something for merging changes in different processes. </p> <p>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</p> <p><strong>DUPE OF <a href="https://stackoverflow.com/questions/320096/django-how-can-i-protect-against-concurrent-modification-of-data-base-entries">Django: How can I protect against concurrent modification of data base entries</a></strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload