python - Best pattern to avoid module globals from being cleaned up -


i'm finding modules defined global objects re-created when module import later:

# mymodule pool = mypoolobject() 

and if accessed code:

def f():    mymodule import pool    print id(pool) 

subsequent calls f print different ids! surprising. expect when f exits, last reference mymodule , global unloaded. can't reference mymodule in caller of f, because, rpc service doesn't know modules calling (it receives pickled objects , calls them).

is there way avoid behavior , keep globals being unloaded? 1 quick workaround add reference in sys:

# mymodule import sys sys._mymodule_pool = mypoolobject() pool = sys._mymodule_pool 

... doesn't seem wouldn't guarantee not unloaded.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -