I'm new to WebDev, explain to me why or why it wouldn't be OK for all users to access a global Lark() parser object?

By lark parser generator pyhon lib I mean:


I’m just thinking if everyone tries to use the same parser object something inside of it might cause an error. OTOH, I don’t know how web servers work exactly…


There are no such things as “global objects” within a production-quality Django deployment. It doesn’t even make sense to suggest this.

In a typical environment, you’re going to have multiple instances of the Python interpreter running, each with their own set of loaded modules. They’re all independent of each other.
And those processes can, when necessary or appropriate, be restarted. So anything set up specifically within an instance would need to be reloaded.

(Yes, there are exceptions to the above, but you would know if you were dealing with one of them.)

1 Like

@KenWhitesell I’m not sure what you’re suggesting though. Are you suggesting that I just stick the parser in a regular global and each user actually will have their own instance? Or are you suggesting that for each user I put the parser object in their Django session?


No, NO globals.

The way Django works is that when a request comes in, Django (the framework) calls a “view”. This view is responsible for creating all objects needed by that invocation of that view. When the view has finished, those objects are disposed of.

Data that needs to be persisted between requests need to be stored externally to the Django process. (Database, memcache, redis, etc)

It may help if you provided more specifics about what it is you’re actually trying to accomplish here.

1 Like