Skip to content

Commit

Permalink
IPython console: Stop debugging before closing clients
Browse files Browse the repository at this point in the history
This prevents freezes when closing Spyder and either a kernel restart or
closing a client is requested while debugging.
  • Loading branch information
ccordoba12 committed Feb 10, 2024
1 parent fd0079c commit 91abbf9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(self, parent, id_,
self.allow_rename = True
self.error_text = None
self.give_focus = give_focus
self.__is_last_client = False

css_path = self.get_conf('css_path', section='appearance')
if css_path is None:
Expand Down Expand Up @@ -555,19 +556,38 @@ def set_color_scheme(self, color_scheme, reset=True):

def close_client(self, is_last_client):
"""Close the client."""
self.__is_last_client = is_last_client
debugging = False

# Needed to handle a RuntimeError. See spyder-ide/spyder#5568.
try:
self.stop_button_click_handler()
# This is required after spyder-ide/spyder#21788 to prevent freezes
# when closing Spyder. That happens not only when a console is in
# debugging mode before closing, but also when a kernel restart is
# requested while debugging.
if self.shellwidget.is_debugging():
debugging = True
self.shellwidget.sig_prompt_ready.connect(self.finish_close)
self.shellwidget.stop_debugging()
else:
self.interrupt_kernel()
except RuntimeError:
pass

# Disconnect timer needed to update elapsed time
if not debugging:
self.finish_close()

def finish_close(self):
"""Actions to take to finish closing the client."""
# Disconnect timer needed to update elapsed time and this slot in case
# it was connected.
try:
self.shellwidget.sig_prompt_ready.disconnect(self.finish_close)
self.timer.timeout.disconnect(self.show_time)
except (RuntimeError, TypeError):
pass

self.shutdown(is_last_client)
self.shutdown(self.__is_last_client)

# Prevent errors in our tests
try:
Expand Down

0 comments on commit 91abbf9

Please sign in to comment.