pythondjangoajaxglobal

Django: global variables in multi-connections


I developed a Django web-application and I tested it in local.. good news, it works!

Know I am trying to move forward. I want to make it reachable via public Internet.. Bad news, it won't work!

The client-side interact with server using Ajax and execute some Python script and get some result to display in the web page.

The problem is that my application/server can't handle multiple connexions!

I clarify:

Mainly, the problem is that when more than one client are served (2 for example), each one will ask the server to run a Python script and, because there is a lot of global variables in the script, the two clients will modify them simultaneously and then bof!

Can multi-threading be a solution? How?


Solution

  • The answer is clear, surely: you should not be using global variables. If you need to store state for a user, do it in the session or the database.