Skip to content

Commit

Permalink
Improve shutdown of console (garbage collect locals).
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed Oct 18, 2023
1 parent e316061 commit 7b739f6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nion/swift/ConsoleDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def __init__(self, locals: typing.Dict[str, typing.Any]) -> None:
self.__history_point: typing.Optional[int] = None
self.__command_cache: typing.Tuple[typing.Optional[int], str] = (None, str()) # Meaning of the tuple: (history_point where the command belongs, command)

def close(self) -> None:
# through experimentation, this is how to ensure the locals are
# garbage collected upon closing.
typing.cast(typing.Dict[str, typing.Any], self.__console.locals).clear()
self.__console.locals = typing.cast(typing.Any, None)
self.__console = typing.cast(typing.Any, None)

@staticmethod
def get_common_prefix(l: typing.List[str]) -> str:
if not l:
Expand Down Expand Up @@ -216,6 +223,8 @@ def emit(self, record: logging.LogRecord) -> None:
def close(self) -> None:
super().close()
self.__text_edit_widget = typing.cast(typing.Any, None)
self.__state_controller.close()
self.__state_controller = typing.cast(typing.Any, None)

def show_prompt(self) -> None:
self.__logging_handler._prompted = True
Expand Down

0 comments on commit 7b739f6

Please sign in to comment.