Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Prevent error when updating sys.path in consoles (IPython console) #22490

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,14 @@ def set_color_scheme(self, color_scheme, reset=True):
)

def update_syspath(self, path_dict, new_path_dict):
"""Update sys.path contents on kernel."""
self.call_kernel(
interrupt=True,
blocking=False).update_syspath(path_dict, new_path_dict)
"""Update sys.path contents in the kernel."""
# Prevent error when the kernel is not available and users open/close
# projects or use the Python path manager.
# Fixes spyder-ide/spyder#21563
if self.kernel_handler is not None:
self.call_kernel(interrupt=True, blocking=False).update_syspath(
path_dict, new_path_dict
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the sys.path contents that was updated be saved somewhere to properly apply it when kernel_handler is available? Or maybe there is no possiblitiy that at some point later on the kernel_handler becomes available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that and concluded it's not necessary because this error can only happen when the kernel is not available (because it errored at startup or the Spyder-kernels version is wrong).


def request_syspath(self):
"""Ask the kernel for sys.path contents."""
Expand Down