def reset(self, new_session=True, aggressive=False):
    'Clear all internal namespaces, and attempt to release references to\n        user objects.\n\n        If new_session is True, a new history session will be opened.\n        '
    self.history_manager.reset(new_session)
    if new_session:
        self.execution_count = 1
    self.last_execution_succeeded = True
    self.last_execution_result = None
    if self.displayhook.do_full_cache:
        self.displayhook.flush()
    if (self.user_ns is not self.user_global_ns):
        self.user_ns.clear()
    ns = self.user_global_ns
    drop_keys = set(ns.keys())
    drop_keys.discard('__builtin__')
    drop_keys.discard('__builtins__')
    drop_keys.discard('__name__')
    for k in drop_keys:
        del ns[k]
    self.user_ns_hidden.clear()
    self.init_user_ns()
    if (aggressive and (not hasattr(self, '_sys_modules_keys'))):
        print('Cannot restore sys.module, no snapshot')
    elif aggressive:
        print('culling sys module...')
        current_keys = set(sys.modules.keys())
        for k in (current_keys - self._sys_modules_keys):
            if k.startswith('multiprocessing'):
                continue
            del sys.modules[k]
    self.alias_manager.clear_aliases()
    self.alias_manager.init_aliases()
    if (os.name == 'posix'):
        for cmd in ('clear', 'more', 'less', 'man'):
            if (cmd not in self.magics_manager.magics['line']):
                self.alias_manager.soft_define_alias(cmd, cmd)
    self.clear_main_mod_cache()
Clear all internal namespaces, and attempt to release references to
user objects.

If new_session is True, a new history session will be opened.
def reset(self, new_session=True, aggressive=False):
    'Clear all internal namespaces, and attempt to release references to\n        user objects.\n\n        If new_session is True, a new history session will be opened.\n        '
    self.history_manager.reset(new_session)
    if new_session:
        self.execution_count = 1
    self.last_execution_succeeded = True
    self.last_execution_result = None
    if self.displayhook.do_full_cache:
        self.displayhook.flush()
    if (self.user_ns is not self.user_global_ns):
        self.user_ns.clear()
    ns = self.user_global_ns
    drop_keys = set(ns.keys())
    drop_keys.discard('__builtin__')
    drop_keys.discard('__builtins__')
    drop_keys.discard('__name__')
    for k in drop_keys:
        del ns[k]
    self.user_ns_hidden.clear()
    self.init_user_ns()
    if (aggressive and (not hasattr(self, '_sys_modules_keys'))):
        print('Cannot restore sys.module, no snapshot')
    elif aggressive:
        print('culling sys module...')
        current_keys = set(sys.modules.keys())
        for k in (current_keys - self._sys_modules_keys):
            if k.startswith('multiprocessing'):
                continue
            del sys.modules[k]
    self.alias_manager.clear_aliases()
    self.alias_manager.init_aliases()
    if (os.name == 'posix'):
        for cmd in ('clear', 'more', 'less', 'man'):
            if (cmd not in self.magics_manager.magics['line']):
                self.alias_manager.soft_define_alias(cmd, cmd)
    self.clear_main_mod_cache()