def new_main_mod(self, filename, modname):
    "Return a new 'main' module object for user code execution.\n\n        ``filename`` should be the path of the script which will be run in the\n        module. Requests with the same filename will get the same module, with\n        its namespace cleared.\n\n        ``modname`` should be the module name - normally either '__main__' or\n        the basename of the file without the extension.\n\n        When scripts are executed via %run, we must keep a reference to their\n        __main__ module around so that Python doesn't\n        clear it, rendering references to module globals useless.\n\n        This method keeps said reference in a private dict, keyed by the\n        absolute path of the script. This way, for multiple executions of the\n        same script we only keep one copy of the namespace (the last one),\n        thus preventing memory leaks from old references while allowing the\n        objects from the last execution to be accessible.\n        "
    filename = os.path.abspath(filename)
    try:
        main_mod = self._main_mod_cache[filename]
    except KeyError:
        main_mod = self._main_mod_cache[filename] = types.ModuleType(modname, doc='Module created for script run in IPython')
    else:
        main_mod.__dict__.clear()
        main_mod.__name__ = modname
    main_mod.__file__ = filename
    main_mod.__nonzero__ = (lambda : True)
    return main_mod
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.
def new_main_mod(self, filename, modname):
    "Return a new 'main' module object for user code execution.\n\n        ``filename`` should be the path of the script which will be run in the\n        module. Requests with the same filename will get the same module, with\n        its namespace cleared.\n\n        ``modname`` should be the module name - normally either '__main__' or\n        the basename of the file without the extension.\n\n        When scripts are executed via %run, we must keep a reference to their\n        __main__ module around so that Python doesn't\n        clear it, rendering references to module globals useless.\n\n        This method keeps said reference in a private dict, keyed by the\n        absolute path of the script. This way, for multiple executions of the\n        same script we only keep one copy of the namespace (the last one),\n        thus preventing memory leaks from old references while allowing the\n        objects from the last execution to be accessible.\n        "
    filename = os.path.abspath(filename)
    try:
        main_mod = self._main_mod_cache[filename]
    except KeyError:
        main_mod = self._main_mod_cache[filename] = types.ModuleType(modname, doc='Module created for script run in IPython')
    else:
        main_mod.__dict__.clear()
        main_mod.__name__ = modname
    main_mod.__file__ = filename
    main_mod.__nonzero__ = (lambda : True)
    return main_mod