Show More
@@ -1575,12 +1575,16 b' Currently the magic system has the following functions:\\n"""' | |||||
1575 |
|
1575 | |||
1576 | # pickle fix. See iplib for an explanation. But we need to make sure |
|
1576 | # pickle fix. See iplib for an explanation. But we need to make sure | |
1577 | # that, if we overwrite __main__, we replace it at the end |
|
1577 | # that, if we overwrite __main__, we replace it at the end | |
1578 |
|
|
1578 | main_mod_name = prog_ns['__name__'] | |
|
1579 | ||||
|
1580 | if main_mod_name == '__main__': | |||
1579 | restore_main = sys.modules['__main__'] |
|
1581 | restore_main = sys.modules['__main__'] | |
1580 | else: |
|
1582 | else: | |
1581 | restore_main = False |
|
1583 | restore_main = False | |
1582 |
|
1584 | |||
1583 | sys.modules[prog_ns['__name__']] = main_mod |
|
1585 | # This needs to be undone at the end to prevent holding references to | |
|
1586 | # every single object ever created. | |||
|
1587 | sys.modules[main_mod_name] = main_mod | |||
1584 |
|
1588 | |||
1585 | stats = None |
|
1589 | stats = None | |
1586 | try: |
|
1590 | try: | |
@@ -1673,9 +1677,15 b' Currently the magic system has the following functions:\\n"""' | |||||
1673 | del prog_ns['__name__'] |
|
1677 | del prog_ns['__name__'] | |
1674 | self.shell.user_ns.update(prog_ns) |
|
1678 | self.shell.user_ns.update(prog_ns) | |
1675 | finally: |
|
1679 | finally: | |
|
1680 | # Ensure key global structures are restored | |||
1676 | sys.argv = save_argv |
|
1681 | sys.argv = save_argv | |
1677 | if restore_main: |
|
1682 | if restore_main: | |
1678 | sys.modules['__main__'] = restore_main |
|
1683 | sys.modules['__main__'] = restore_main | |
|
1684 | else: | |||
|
1685 | # Remove from sys.modules the reference to main_mod we'd | |||
|
1686 | # added. Otherwise it will trap references to objects | |||
|
1687 | # contained therein. | |||
|
1688 | del sys.modules[main_mod_name] | |||
1679 | self.shell.reloadhist() |
|
1689 | self.shell.reloadhist() | |
1680 |
|
1690 | |||
1681 | return stats |
|
1691 | return stats |
General Comments 0
You need to be logged in to leave comments.
Login now