delete all user-defined global variables in an imported python module -


i have python script imports series of other python scripts name through __import__, calls script's main function. after each import complete, want reclaim memory allocated script, of them create large in-memory structures globals (i don't have control on globals part.)

my intended approach loop through vars() , delete each non-private variable, thusly:

for m in ['imp1', 'imp2', 'imp3']:      this_mod = __import__(m)     this_mod.main()      # delete module's globals     mvars = [ in vars(this_mod) if not i.startswith('__') ]     var in mvars:         delattr(this_mod, var) 

is reasonable approach and/or there gotchas should aware of?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -