Show More
@@ -1410,7 +1410,7 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1410 | 1410 |
|
|
1411 | 1411 |
|
|
1412 | 1412 | |
|
1413 |
|
|
|
1413 | def reset(self, new_session=True, aggressive=False): | |
|
1414 | 1414 |
|
|
1415 | 1415 | user objects. |
|
1416 | 1416 | |
@@ -1447,6 +1447,15 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1447 | 1447 | |
|
1448 | 1448 |
|
|
1449 | 1449 |
|
|
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 |
|
|
1452 | 1461 |
|
@@ -491,6 +491,10 b' class NamespaceMagics(Magics):' | |||
|
491 | 491 | we do a 'hard' reset, giving you a new session and removing all |
|
492 | 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 | 498 | in : reset input history |
|
495 | 499 | |
|
496 | 500 | out : reset output history |
@@ -533,8 +537,8 b' class NamespaceMagics(Magics):' | |||
|
533 | 537 | such as the ipython notebook interface, will reset the namespace |
|
534 | 538 | without confirmation. |
|
535 | 539 | """ |
|
536 |
opts, args = self.parse_options(parameter_s, |
|
|
537 |
if |
|
|
540 | opts, args = self.parse_options(parameter_s, "sf", "aggressive", mode="list") | |
|
541 | if "f" in opts: | |
|
538 | 542 | ans = True |
|
539 | 543 | else: |
|
540 | 544 | try: |
@@ -552,7 +556,7 b' class NamespaceMagics(Magics):' | |||
|
552 | 556 | for i in self.who_ls(): |
|
553 | 557 | del(user_ns[i]) |
|
554 | 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 | 561 | # reset in/out/dhist/array: previously extensinions/clearcmd.py |
|
558 | 562 | ip = self.shell |
@@ -331,6 +331,7 b' class InteractiveShellApp(Configurable):' | |||
|
331 | 331 | # flush output, so itwon't be attached to the first cell |
|
332 | 332 | sys.stdout.flush() |
|
333 | 333 | sys.stderr.flush() |
|
334 | self.shell._sys_modules_keys = set(sys.modules.keys()) | |
|
334 | 335 | |
|
335 | 336 | def _run_exec_lines(self): |
|
336 | 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