fix: do not crash when using IPython but no kernel is available#17683
fix: do not crash when using IPython but no kernel is available#17683maartenbreddels wants to merge 4 commits intoastropy:mainfrom
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Hi @maartenbreddels, thanks for your work |
|
More accurately, could you point to where in solara an IPython shell is created and explain why this is seemingly run automatically through pytest ? |
|
pre-commit.ci autofix |
as other because there is no logger section
|
I think you could have a Jupyter session active with no active kernel if you go into the option and says "kills all kernels". Solara is being used in Jdaviz, which I am also working on. Since this is a blocker for us downstream, I am going to approve. But I will wait to merge in case @astrofrog wants to review too or @neutrinoceros objects to this. Thanks! |
|
I'll probably end up accepting this without change, but since it fixes a mistake I made I'd like to make sure I understand the approach so I don't do it again 🥲 |
| _WITHIN_IPYTHON = False | ||
| else: | ||
| _WITHIN_IPYTHON = True | ||
| from IPython import get_ipython |
There was a problem hiding this comment.
making the imports in L321,341,380 redundant – this might be the more elegant way anyway
There was a problem hiding this comment.
Good catch! I took the liberty to add a commit to remove them.
that are no longer necessary
I think in Jupyter this does not happen, as even after killing all kernels calling |
|
I think we can ignore? 😅 |
dhomeier
left a comment
There was a problem hiding this comment.
I don't understand the full repercussions of running this in the Solara environment either, but since get_ipython is needed and used anyway, don't see any drawbacks to this change.
|
@neutrinoceros , are you okay with merging this? Please advise. Thanks! |
|
Ok I think I get it now. The name |
We do this with all the other methods, so it makes sense to do it here as well. This should fix #965 and is an alternative to astropy/astropy#17683
|
thank you for being critical. While trying to explain why this PR was needed, I discovered I made a mistake in my reasoning. I misremembered that get_ipython should return the kernel, but it should return the shell ( https://ipython.readthedocs.io/en/8.27.0/api/generated/IPython.core.getipython.html ) |
…#990) We do this with all the other methods, so it makes sense to do it here as well. This should fix #965 and is an alternative to astropy/astropy#17683
Description
This pull request is to address a crash of astropy when using it in combination with solara (see widgetti/solara#965)
When _WITHIN_IPYTHON was true, it was assumed a kernel would exists. However, looking at
https://github.com/ipython/ipython/blob/637e037d668db7aebe61ae04261ebfc5cb7f32c5/IPython/core/interactiveshell.py#L788
This only means an interactive shell is available, so we should also check if get_ipython() returns a kernel object.
Fixes widgetti/solara#965