Skip to content

Commit

Permalink
Merge branch 'patch-29' into separate_cmd_input
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Apr 15, 2020
2 parents 2559fb3 + 7273d93 commit 26b8329
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
import uuid
import psutil
import threading

# Third party imports
from IPython.core import release as ipy_release
Expand Down Expand Up @@ -3095,10 +3096,11 @@ def test_ipython_magic(main_window, qtbot, tmpdir, ipython, test_cell_magic):
os.remove(to_text_string(write_file))


def test_files_leak(main_window, qtbot):
"""Tests if files are left open when closing things."""
def test_leaks(main_window, qtbot):
"""Tests if files or threads are left open when closing things."""
proc = psutil.Process()
number_files = len(proc.open_files())
number_threads = threading.active_count()

# Close everything we can think of
main_window.editor.close_file()
Expand All @@ -3107,10 +3109,12 @@ def test_files_leak(main_window, qtbot):
main_window.console.close_error_dlg()
main_window.switcher.close()
for client in main_window.ipyconsole.get_clients():
# Force close to avoid shutdown thread
main_window.ipyconsole.close_client(client=client, force=True)

# Make sure no new open files popped up
assert number_files == len(proc.open_files())
assert number_threads == threading.active_count()


if __name__ == "__main__":
Expand Down
11 changes: 11 additions & 0 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(self, ipyclient, additional_options, interpreter_versions,
# set in the qtconsole constructor. See spyder-ide/spyder#4806.
self.set_bracket_matcher_color_scheme(self.syntax_style)

self.shutdown_thread = None
self.kernel_manager = None
self.kernel_client = None
handlers = {
Expand Down Expand Up @@ -126,6 +127,16 @@ def stop_kernel_channels(self):
"""Stop kernel channels."""
if self.kernel_client is not None:
self.kernel_client.stop_channels()
if self.shutdown_thread is not None:
self.shutdown_thread = None

def will_close(self):
"""Close shell"""
self.kernel_manager.stop_restarter()
if self.shutdown_thread is None:
# Make sure the channels are stopped
self.stop_kernel_channels()
super(ShellWidget, self).will_close()

def call_kernel(self, interrupt=False, blocking=False, callback=None,
timeout=None):
Expand Down

0 comments on commit 26b8329

Please sign in to comment.