Hi all,
Has anyone encountered an issue where a module (in my case my Globals module) seems to get reinstantiated and variables lose the values they were assigned?
I have a Globals.myvar variable that I declare in the Globals module, and assign it an empty string “”.
I import the module in my client code and my server module.
I set the value of it from a server module (Globals.myvar = “hello”) but then when I call the value later from client code, I get the previous empty string “”.
I have checked that the server module correctly sets the value when it runs with a print statement. But when I run a print statement of the same variable from the client code, it comes up empty.
Any ideas what could be causing that? I have not set its value elsewhere to be empty other than in the Globals module itself.
The python interpreter running on the client is different and independent from the one on the server.
The client starts its own interpreter and a Globals module can be used to share variables across forms. That Globals will be alive as long a the app is alive in that browser’s tab.
The server knows nothing about that. The server starts its own interpreter and imports its own Globals. Then, unless your plan allows it and you enable persistent server, the server starts a new interpreter every time there is a server call or an http endpoint call, and creates a new Globals at every call.
3 Likes
Hmm, well that is good to know. I could have sworn I had persisted Globals variables between server and client code before, but I guess that wasn’t the case. I don’t have the required plan at the moment to set up persistent server.
Would the only other way to do it be writing to database or Google Doc?
Database is going to be much faster than Google docs.
May not apply in all situations, but since you’re calling a server function from the client, the server function can return a dictionary of updates to globals that the client can then apply.
1 Like
Yep, I was thinking of doing that as well… and it works this way.
Thanks both for your responses.
May not apply in all situations, but since you’re calling a server function from the client, the server function can return a dictionary of updates to globals that the client can then apply.
Definitely not the case. Client and server are separate computers, and may be thousands of miles apart. They do not share memory. At all.