TenjintShell.new_main_mod¶
-
TenjintShell.
new_main_mod
(filename, modname)¶ Return a new ‘main’ module object for user code execution.
filename
should be the path of the script which will be run in the module. Requests with the same filename will get the same module, with its namespace cleared.modname
should be the module name - normally either ‘__main__’ or the basename of the file without the extension.When scripts are executed via %run, we must keep a reference to their __main__ module around so that Python doesn’t clear it, rendering references to module globals useless.
This method keeps said reference in a private dict, keyed by the absolute path of the script. This way, for multiple executions of the same script we only keep one copy of the namespace (the last one), thus preventing memory leaks from old references while allowing the objects from the last execution to be accessible.