Fix shell_magic load failure on Windows by lazy-initializing shell process#364
Merged
blink1073 merged 2 commits intoCalysto:mainfrom Mar 13, 2026
Merged
Fix shell_magic load failure on Windows by lazy-initializing shell process#364blink1073 merged 2 commits intoCalysto:mainfrom
blink1073 merged 2 commits intoCalysto:mainfrom
Conversation
…ndows Previously, ShellMagic.__init__ eagerly called start_process(), which launched powershell immediately on Windows. On some systems (e.g. Windows 7), the pexpect prompt detection timed out, raising an exception that propagated up through register_magics() and caused reload_magics() to log a spurious "Can't load shell_magic.py" error — preventing the magic from loading at all. The fix defers process startup to the first call to eval(), so shell_magic.py loads cleanly and any startup errors only surface when %shell is actually used. Closes Calysto#247
_make_kernel_with_parent created a ZMQ PUB socket but never closed it, unlike get_kernel() which uses weakref.finalize. The open sockets were GC'd during later tests, causing ResourceWarning → PytestUnraisableExceptionWarning failures when the full test suite ran.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #364 +/- ##
=======================================
Coverage 90.95% 90.95%
=======================================
Files 51 51
Lines 2874 2875 +1
Branches 402 403 +1
=======================================
+ Hits 2614 2615 +1
Misses 181 181
Partials 79 79 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #247
Summary
ShellMagic.__init__was eagerly callingstart_process(), which on Windows immediately tried to spawn a powershell process via pexpectpexpect.TIMEOUTexceptionregister_magics()toreload_magics(), which logged a spurious"Can't load shell_magic.py"error and left the magic unregisteredstart_process()call from__init__and add lazy initialization ineval()— the process is now started on first useTest plan
tests/magics/test_shell_magic.pytests all pass (verified locally)python -m octave_kernel.check(or any MetaKernel-based kernel check) no longer shows the "Can't load shell_magic.py" error%shell/!commands still work normally when invoked