Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Django blocks simultaneous requests within the same session?

I tried to add sleep(30) at the first line of my view. After that I opened this page in two browser tabs. The first tab loaded the page after 30 seconds, and the second one loaded it in 60 seconds. In the meantime I was able to open pages from another pc just fine. So it looks like Django blocks the concurrent requests from the same client.

This is very well for my app. And I'd like to be sure my site will work this way in the future. However I have not found any documentation or articles describing such Django behaviour. So I'm still not sure if this is a feature or just fortune. Could somebody please explain how and why this works?

What I actually need is to block the session while view is processing. Of course I can use some flags or db transactions. But I'd not like to add a feature that is already implemented in Django.

I use python 2.6.5, django 1.4, ubuntu server, nginx and uwsgi. Tried both postgresql and sqlite.

My uwsgi settings:

<uwsgi>
    <pythonpath>/home/admin/app/src</pythonpath>
    <app mountpoint="/">
        <script>deploy.wsgi</script>
    </app>
    <workers>4</workers><!-- Not sure this is needed -->
    <processes>2</processes>
</uwsgi>

I also got same effect with runserver command.

like image 918
raacer Avatar asked Sep 16 '26 04:09

raacer


1 Answers

Actually Django does not block simultaneous requests.

If I run two browsers (for example chrome and firefox) with the same session (by copying the sessionid cookie from the first browser to the second one), blocking does not happen. So, this is a browser feature, and it's not related to Django anyhow. This means I still need to add some blocking feature by myself to make the code safe.

like image 113
raacer Avatar answered Sep 19 '26 14:09

raacer