Skip to content

Instantly share code, notes, and snippets.

@dyerrington
Last active December 12, 2020 18:50
Show Gist options
  • Save dyerrington/2e67ee1556c1f23773ab9952c6cd105a to your computer and use it in GitHub Desktop.
Save dyerrington/2e67ee1556c1f23773ab9952c6cd105a to your computer and use it in GitHub Desktop.
Jupyter restarting patch fix for Apple M1 Processors.

Jupyter Kernel Keeps Restarting Bug Fix

For those of us who took the plunge into the Apple M1 danger zone, we know that it's unlikely to be bug-free regarding application code that depends on set assumptions about environment behavior. One such bug that will likely see a fix soon in the main branch of Jupyter in short order is the Juptyer subsystem responsible for handling event callbacks from the front-end. Fortunately, the fix is relatively minimal and involves updating the assumptions whether or not the context of which Jupyter is running in a WX compatible context (I believe this to mean as a GUI application or not).

The problem that causes the restart in the kernel is a set of states that must be established for the Kernel to run properly, but are never set due to the check for the WX environment not cleanly being handled given the envrionmetnal variables that are reported by M1 vs previous processor architectures on Mac.

Applying the patch

With the patch file attached to this gist, apply it to your ~/anaconda3/lib/python3.x/site-packages/ipykernel/eventloops.py) (x is your version of Python) file.

To apply the patch, assuming you've downloaded the patch to your ~/ home directory, first make a backup of the file referenced above, then use the patch command to update your file.

cd ~/anaconda3/lib/python3.8/site-packages/ipykernel/
patch -b < ~/m1_fix_5.1.2.event_loops_py.patch
--- eventloops.py-orig 2020-12-12 10:22:08.633178000 -0800
+++ eventloops.py 2020-12-12 10:22:56.335735100 -0800
@@ -20,7 +20,7 @@
Checks if we are on OS X 10.9 or greater.
"""
- return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9')
+ return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9') and platform.mac_ver()[2] != 'arm64'
def _notify_stream_qt(kernel, stream):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment