MCPcopy Create free account
hub / github.com/ipython/ipython / reset

Method reset

IPython/core/interactiveshell.py:1412–1464  ·  view source on GitHub ↗

Clear all internal namespaces, and attempt to release references to user objects. If new_session is True, a new history session will be opened.

(self, new_session=True)

Source from the content-addressed store, hash-verified

1410 [m.__dict__ for m in self._main_mod_cache.values()]
1411
1412 def reset(self, new_session=True):
1413 """Clear all internal namespaces, and attempt to release references to
1414 user objects.
1415
1416 If new_session is True, a new history session will be opened.
1417 """
1418 # Clear histories
1419 self.history_manager.reset(new_session)
1420 # Reset counter used to index all histories
1421 if new_session:
1422 self.execution_count = 1
1423
1424 # Reset last execution result
1425 self.last_execution_succeeded = True
1426 self.last_execution_result = None
1427
1428 # Flush cached output items
1429 if self.displayhook.do_full_cache:
1430 self.displayhook.flush()
1431
1432 # The main execution namespaces must be cleared very carefully,
1433 # skipping the deletion of the builtin-related keys, because doing so
1434 # would cause errors in many object's __del__ methods.
1435 if self.user_ns is not self.user_global_ns:
1436 self.user_ns.clear()
1437 ns = self.user_global_ns
1438 drop_keys = set(ns.keys())
1439 drop_keys.discard('__builtin__')
1440 drop_keys.discard('__builtins__')
1441 drop_keys.discard('__name__')
1442 for k in drop_keys:
1443 del ns[k]
1444
1445 self.user_ns_hidden.clear()
1446
1447 # Restore the user namespaces to minimal usability
1448 self.init_user_ns()
1449
1450 # Restore the default and user aliases
1451 self.alias_manager.clear_aliases()
1452 self.alias_manager.init_aliases()
1453
1454 # Now define aliases that only make sense on the terminal, because they
1455 # need direct access to the console in a way that we can't emulate in
1456 # GUI or web frontend
1457 if os.name == 'posix':
1458 for cmd in ('clear', 'more', 'less', 'man'):
1459 if cmd not in self.magics_manager.magics['line']:
1460 self.alias_manager.soft_define_alias(cmd, cmd)
1461
1462 # Flush the private list of module references kept for script
1463 # execution protection
1464 self.clear_main_mod_cache()
1465
1466 def del_var(self, varname, by_name=False):
1467 """Delete a variable from the various namespaces, so that, as

Callers 1

atexit_operationsMethod · 0.95

Calls 6

init_user_nsMethod · 0.95
clear_main_mod_cacheMethod · 0.95
clear_aliasesMethod · 0.80
init_aliasesMethod · 0.80
soft_define_aliasMethod · 0.80
flushMethod · 0.45

Tested by

no test coverage detected