Multiple, simultaneous user sessions?

This is, in fact, the default. Here is how it works.

  1. When User A visits your App’s web page, their browser receives its own copy of the App’s Client modules, and any modules that they import. This is a Python program running in A’s browser, on A’s own machine.
  2. The same thing happens with User B, C, D, … Each gets their own independent copy, or instance, running independently.
  3. Because these copies are all independent, they do not share any variables. However, where some kind of sharing is necessary, they can call upon Anvil’s database features, to save values in a database shared by all copies of the App.
  4. When any of these instances calls a Server Module function, Anvil starts a new copy of a Server-side program, containing that function, to service the call. That program generally runs until the function completes.
  5. If the called function is in an Uplink program, it is your responsibility to make sure that the Uplink program has already been started, so that it can respond. Each incoming request starts in its own Python thread of execution, so calls may overlap. (Be careful with any global variables in the Uplink program!)

Edit 1: I strongly encourage you to use the Docs link above, and the Search feature, for more detail on these topics. Search reaches into the docs and this forum, so it can find answers for you in both places.

Edit 2: If Uplink is essential to the App’s operation, then your Uplinked functions must be thread-safe, in the Python sense. Two or more instances of the Uplinked function (or functions it calls) may be running at the same time, so they should not be writing to the same global variable. (This extends to other shared global resources, such as local database connections, or files.) You don’t want a call from User A to screw up a call from User B. Function-local variables are fine, though, as each instance gets its own local variables.

2 Likes