Open dalthviz opened 6 months ago
Thanks @dalthviz. I'll take care of this one.
@impact27, how do you think we should handle this error?
Traceback (most recent call last):
File "C:\Users\dalth\anaconda3\envs\spyder6_test\Lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 898, in update_path
self.get_widget().update_path(path_dict, new_path_dict)
File "C:\Users\dalth\anaconda3\envs\spyder6_test\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\main_widget.py", line 2206, in update_path
shell.update_syspath(path_dict, new_path_dict)
File "C:\Users\dalth\anaconda3\envs\spyder6_test\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\shell.py", line 685, in update_syspath
self.call_kernel(
File "C:\Users\dalth\anaconda3\envs\spyder6_test\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\shell.py", line 349, in call_kernel
return self.kernel_handler.kernel_comm.remote_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'kernel_comm'
It seems the kernel takes too much time to start, so kernel_handler
is not available when call_kernel
is called.
Of course we could catch that exception and pass. But then all those calls to call_kernel
wouldn't have any effect, which would lead to a bad user experience for users. For instance, in this case users would think that the paths they added in our Python path manager were automatically appended to sys.path
in the console, but that wouldn't be the case.
I didn't check the specifics, but in general the initial kernel setup is done in send_spyder_kernel_configuration
. It should be able to do a full setup in case of kernel restart. Before this function is called the kernel is not ready anyway. So the path for example should be added there.
the set_kernel_configuration
method allows to set a configuration before the kernel is ready. It also survives a restart.
What is strange is that both the Shellwidget
and the kernel_handler
are created in create_new_client
, so there shouldn't be a time where kernel_handler
is None
? unless the eventloop runs while create_new_client
is executed?
What is strange is that both the Shellwidget and the kernel_handler are created in create_new_client, so there shouldn't be a time where kernel_handler is None?
I think that can happen when there's an error starting the kernel:
In that case kernel_handler
will remain as None
in ShellWidget
. So, perhaps catching that error and pass is not a bad idea?
@impact27, I saw that you opened PR #21895 to address this. Thanks for your help with that!
But could you explain your rationale for that change?
The sys.path is set in two ways: by setting the "SPY_PYTHONPATH" environment variable and by calling update_path. the first way is problematic because in case of a restart after changing the python path the old python path is restored. The second way is problematic because by calling remote_call directly without checking for the kernel state you can end up with the error in this issue.
In fact this is true of most of the config that is set by an environment variable, I will change these as well.
Issue Report Checklist
Problem Description
Installed Spyder 6.0.0a4 in a new env and in the first launch I got a couple of tracebacks printed in the Anaconda prompt instance from where I launched Spyder. Also, I think I had a custom interpreter selected which didn't comply with the minimum
spyder-kernels
version required for Spyder 6.0.0a4What steps reproduce the problem?
What is the expected output? What do you see instead?
No tracebacks when launching Spyder. Couple of tracebacks are shown over the Anaconda prompt instance used to launch Spyder
Paste Traceback/Error Below (if applicable)
Versions
Dependencies