Show More
@@ -1410,7 +1410,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1410 |
|
|
1410 | return [self.user_ns, self.user_global_ns, self.user_ns_hidden] + \ | |
1411 |
|
|
1411 | [m.__dict__ for m in self._main_mod_cache.values()] | |
1412 |
|
1412 | |||
1413 |
|
|
1413 | def reset(self, new_session=True, aggressive=False): | |
1414 |
|
|
1414 | """Clear all internal namespaces, and attempt to release references to | |
1415 | user objects. |
|
1415 | user objects. | |
1416 |
|
1416 | |||
@@ -1447,6 +1447,15 b' class InteractiveShell(SingletonConfigurable):' | |||||
1447 |
|
1447 | |||
1448 |
|
|
1448 | # Restore the user namespaces to minimal usability | |
1449 |
|
|
1449 | self.init_user_ns() | |
|
1450 | if aggressive and not hasattr(self, "_sys_modules_keys"): | |||
|
1451 | print("Cannot restore sys.module, no snapshot") | |||
|
1452 | elif aggressive: | |||
|
1453 | print("culling sys module...") | |||
|
1454 | current_keys = set(sys.modules.keys()) | |||
|
1455 | for k in current_keys - self._sys_modules_keys: | |||
|
1456 | if k.startswith("multiprocessing"): | |||
|
1457 | continue | |||
|
1458 | del sys.modules[k] | |||
1450 |
|
1459 | |||
1451 |
|
|
1460 | # Restore the default and user aliases | |
1452 |
|
|
1461 | self.alias_manager.clear_aliases() |
@@ -491,6 +491,10 b' class NamespaceMagics(Magics):' | |||||
491 | we do a 'hard' reset, giving you a new session and removing all |
|
491 | we do a 'hard' reset, giving you a new session and removing all | |
492 | references to objects from the current session. |
|
492 | references to objects from the current session. | |
493 |
|
493 | |||
|
494 | --aggressive: Try to aggressively remove modules from sys.modules ; this | |||
|
495 | may allow you to reimport Python modules that have been updated and | |||
|
496 | pick up changes, but can have unattended consequences. | |||
|
497 | ||||
494 | in : reset input history |
|
498 | in : reset input history | |
495 |
|
499 | |||
496 | out : reset output history |
|
500 | out : reset output history | |
@@ -533,8 +537,8 b' class NamespaceMagics(Magics):' | |||||
533 | such as the ipython notebook interface, will reset the namespace |
|
537 | such as the ipython notebook interface, will reset the namespace | |
534 | without confirmation. |
|
538 | without confirmation. | |
535 | """ |
|
539 | """ | |
536 |
opts, args = self.parse_options(parameter_s, |
|
540 | opts, args = self.parse_options(parameter_s, "sf", "aggressive", mode="list") | |
537 |
if |
|
541 | if "f" in opts: | |
538 | ans = True |
|
542 | ans = True | |
539 | else: |
|
543 | else: | |
540 | try: |
|
544 | try: | |
@@ -552,7 +556,7 b' class NamespaceMagics(Magics):' | |||||
552 | for i in self.who_ls(): |
|
556 | for i in self.who_ls(): | |
553 | del(user_ns[i]) |
|
557 | del(user_ns[i]) | |
554 | elif len(args) == 0: # Hard reset |
|
558 | elif len(args) == 0: # Hard reset | |
555 |
self.shell.reset(new_session = |
|
559 | self.shell.reset(new_session=False, aggressive=("aggressive" in opts)) | |
556 |
|
560 | |||
557 | # reset in/out/dhist/array: previously extensinions/clearcmd.py |
|
561 | # reset in/out/dhist/array: previously extensinions/clearcmd.py | |
558 | ip = self.shell |
|
562 | ip = self.shell |
@@ -331,6 +331,7 b' class InteractiveShellApp(Configurable):' | |||||
331 | # flush output, so itwon't be attached to the first cell |
|
331 | # flush output, so itwon't be attached to the first cell | |
332 | sys.stdout.flush() |
|
332 | sys.stdout.flush() | |
333 | sys.stderr.flush() |
|
333 | sys.stderr.flush() | |
|
334 | self.shell._sys_modules_keys = set(sys.modules.keys()) | |||
334 |
|
335 | |||
335 | def _run_exec_lines(self): |
|
336 | def _run_exec_lines(self): | |
336 | """Run lines of code in IPythonApp.exec_lines in the user's namespace.""" |
|
337 | """Run lines of code in IPythonApp.exec_lines in the user's namespace.""" |
General Comments 0
You need to be logged in to leave comments.
Login now