An Anvil app involves two interpreters, one real Python running on the server and one Pythonish running on the client.
Whatever runs on the client stays on the client. When an app starts, the browser starts the Python interpreter (Skulpt), imports (i.e. interprets from scratch) all the required forms and client modules and starts the session. Any global variable is created here, is not imported or inherited from previous sessions.
Unless you call server functions and explicitly send some data to the server, you are on your own client.
The interpreter running on the server instead can be shared across sessions of different users, provided the “Keep the server running” option is checked. When the client contacts the server, If an interpreter is already running it will respond and it will be able to see any global variable created in any previous call. If an interpreter is not yet running, it will be start and create all the globals from scratch.
Summary:
- The life of the interpreter on the client is well defined: from the time the app starts until the browser is closed
- The life of the interpreter on the server without “Keep the server running” is well defined too: it starts every time the client contacts the server
- The life of the interpreter on the server with “Keep the server running” is unpredictable: two consecutive calls from the same app could land on two different servers, and both the interpreters will have independent globals. Or, two calls from two different apps could land on the same server and the second one will see all the globals created by the first one