From d8199513a6e91f00a74b46acfc3e69abac9b35b8 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Tue, 19 Sep 2023 08:10:48 +0200 Subject: [PATCH] cleanup --- .../ipythonconsole/widgets/main_widget.py | 9 +++-- .../plugins/ipythonconsole/widgets/shell.py | 38 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py index 4dd4c2d594b..d871317d573 100644 --- a/spyder/plugins/ipythonconsole/widgets/main_widget.py +++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py @@ -1454,10 +1454,11 @@ def create_new_client(self, give_focus=True, filename='', special=None, str_id='A') # Find what kind of kernel we want - if self.get_conf('pylab/autoload'): - special = "pylab" - elif self.get_conf('symbolic_math'): - special = "sympy" + if special is None: + if self.get_conf('pylab/autoload'): + special = "pylab" + elif self.get_conf('symbolic_math'): + special = "sympy" client = ClientWidget( self, diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py index 1efa78b8b17..cbf15fba073 100644 --- a/spyder/plugins/ipythonconsole/widgets/shell.py +++ b/spyder/plugins/ipythonconsole/widgets/shell.py @@ -204,7 +204,7 @@ def spyder_kernel_ready(self): """ if self.kernel_handler is None: return False - return ( + return (self.is_kernel_configured and self.kernel_handler.connection_state == KernelConnectionState.SpyderKernelReady) @@ -304,7 +304,8 @@ def handle_kernel_is_ready(self): self.kernel_handler.connection_state == KernelConnectionState.SpyderKernelReady ): - self.setup_spyder_kernel() + self.kernel_connect_sig() + self.send_spyder_kernel_configuration() def _started_channels(self): """Make a history request""" @@ -393,9 +394,9 @@ def is_external_kernel(self): if self.kernel_handler is None: return False return self.kernel_handler.kernel_spec_dict is None - - def setup_spyder_kernel(self): - """Setup spyder kernel""" + + def kernel_connect_sig(self): + """Connect signals for kernel.""" if not self._init_kernel_setup: # Only do this setup once self._init_kernel_setup = True @@ -417,21 +418,9 @@ def setup_spyder_kernel(self): for request_id, handler in self.kernel_comm_handlers.items(): self.kernel_handler.kernel_comm.register_call_handler( request_id, handler) - - # Setup to do after restart - # Check for fault and send config - self.kernel_handler.poll_fault_text() - - self.send_spyder_kernel_configuration() - - run_lines = self.get_conf('startup/run_lines') - if run_lines: - self.execute(run_lines, hidden=True) - - if self.get_conf('startup/use_run_file'): - run_file = self.get_conf('startup/run_file') - if run_file: - self.execute(f"exec(open({run_file}))", hidden=True) + else: + # kernel might have restarted + self.kernel_handler.poll_fault_text() def send_spyder_kernel_configuration(self): """Send kernel configuration to spyder kernel.""" @@ -470,6 +459,15 @@ def send_spyder_kernel_configuration(self): callback=self.kernel_configure_callback ).set_configuration(self._kernel_configuration) + run_lines = self.get_conf('startup/run_lines') + if run_lines: + self.execute(run_lines, hidden=True) + + if self.get_conf('startup/use_run_file'): + run_file = self.get_conf('startup/run_file') + if run_file: + self.execute(f"exec(open({run_file}))", hidden=True) + self.is_kernel_configured = True def set_kernel_configuration(self, key, value):