Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Cordoba <[email protected]>
  • Loading branch information
impact27 and ccordoba12 authored Sep 19, 2022
1 parent 66b9a15 commit 2db91a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
19 changes: 16 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,14 @@ def change_client_mpl_conf(o=options, c=client):
elif restart and restart_all:
self.restart_kernel(client, ask_before_restart=False)

if (((pylab_restart and current_client_backend_require_restart)
or restart_needed) and restart_current and current_client):
if (
(
(pylab_restart and current_client_backend_require_restart)
or restart_needed
)
and restart_current
and current_client
):
self.restart_kernel(current_client, ask_before_restart=False)

# ---- Private methods
Expand Down Expand Up @@ -950,6 +956,7 @@ def _create_client_for_kernel(self):
(connection_file, hostname, sshkey, password, ok) = connect_output
if not ok:
return

try:
# Fix path
connection_file = self.find_connection_file(connection_file)
Expand All @@ -958,6 +965,7 @@ def _create_client_for_kernel(self):
_("Unable to connect to "
"<b>%s</b>") % connection_file)
return

self.create_client_for_kernel(
connection_file, hostname, sshkey, password)

Expand Down Expand Up @@ -1069,6 +1077,7 @@ def add_tab(self, client, name, filename='', give_focus=True):
self.activateWindow()
client.get_control().setFocus()
self.update_tabs_text()

# Register client
self.register_client(client)

Expand Down Expand Up @@ -1311,6 +1320,7 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False,
handlers=self.registered_spyder_kernel_handlers,
initial_cwd=initial_cwd,
)

# Add client to widget
self.add_tab(
client, name=client.get_name(), filename=filename,
Expand All @@ -1322,6 +1332,7 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False,
is_pylab=is_pylab,
is_sympy=is_sympy
)

try:
kernel_handler = self.get_cached_kernel(kernel_spec, cache=cache)
except Exception as e:
Expand Down Expand Up @@ -1358,13 +1369,15 @@ def create_client_for_kernel(self, connection_file, hostname, sshkey,
new_slave_ord = ord(cl.id_['str_id'])
if new_slave_ord > slave_ord:
slave_ord = new_slave_ord

# Set full client name
client_id = dict(int_id=master_client.id_['int_id'],
str_id=chr(slave_ord + 1))
else:
# If we couldn't find a client with the same connection file,
# it means this is a new master client
self.master_clients += 1

# Set full client name
client_id = dict(int_id=str(self.master_clients), str_id='A')

Expand Down Expand Up @@ -1580,7 +1593,7 @@ def close_all_clients(self):
client.close_client(is_last_client)
open_clients.remove(client)

# wait all closing KernelHandler.
# Wait for all KernelHandler's to shutdown.
for client in self.clients:
if client.kernel_handler:
client.kernel_handler.wait_shutdown_thread()
Expand Down
25 changes: 15 additions & 10 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ShellWidget(NamepaceBrowserWidget, HelpWidget, DebuggingWidget,
# Request plugins to send additional configuration to the kernel
sig_config_kernel_requested = Signal()

# To notify of kernel connection / deconnection
# To notify of kernel connection / disconnection
sig_shellwidget_created = Signal(object)
sig_shellwidget_deleted = Signal(object)

Expand All @@ -175,7 +175,7 @@ def __init__(self, ipyclient, additional_options, interpreter_versions,
self.ipyclient = ipyclient
self.additional_options = additional_options
self.interpreter_versions = interpreter_versions
self.kernel_handler = False
self.kernel_handler = None
self._cwd = ''

# Keyboard shortcuts
Expand Down Expand Up @@ -214,16 +214,17 @@ def is_spyder_kernel(self):
return False
return self.kernel_handler.known_spyder_kernel

def connect_kernel(self, kernel):
"""Connect to kernel."""
def connect_kernel(self, kernel_handler):
"""Connect to the kernel using our handler."""
# Kernel client
kernel_client = kernel.kernel_client
kernel_client = kernel_handler.kernel_client
kernel_client.stopped_channels.connect(self.notify_deleted)
kernel_client.start_channels()
self.kernel_client = kernel_client

self.kernel_manager = kernel.kernel_manager
self.kernel_handler = kernel
self.kernel_manager = kernel_handler.kernel_manager
self.kernel_handler = kernel_handler

# Send message to kernel to check status
self.check_spyder_kernel()
self.sig_shellwidget_created.emit(self)
Expand All @@ -238,12 +239,13 @@ def shutdown(self, shutdown_kernel=True):
return
self.shutting_down = True
self.close_kernel(shutdown_kernel)
super(ShellWidget, self).shutdown()
super().shutdown()

def close_kernel(self, shutdown_kernel=True):
"""Close the kernel"""
self.kernel_handler.close(shutdown_kernel)
# reset state

# Reset state
self.reset_kernel_state()

def reset_kernel_state(self):
Expand Down Expand Up @@ -292,11 +294,13 @@ def setup_spyder_kernel(self):
"""Setup spyder kernel"""
self.kernel_handler.open_comm(self.spyder_kernel_comm)

# For completion
# For completions
self.kernel_client.control_channel.message_received.connect(
self._dispatch)

# Redefine the complete method to work while debugging.
self._redefine_complete_for_dbg(self.kernel_client)

# Send configuration
self.send_spyder_kernel_configuration()

Expand All @@ -311,6 +315,7 @@ def send_spyder_kernel_configuration(self):
self.set_color_scheme(self.syntax_style, reset=False)

ffn = self.kernel_handler.get_fault_filename()

# Enable faulthandler
if ffn:
# To display faulthandler
Expand Down

0 comments on commit 2db91a1

Please sign in to comment.