Remote Jupyter kernel (over ssh) crashes when X11 connection is closed

487 Views Asked by At

My python analysis setup:

I run long sessions of a Python3 console on a ssh server. I keep them running inside tmux across multiple connections. I either run IPython3, or more recently I launch a jupyter kernel that I connect to a console using jupyter console --existing kernel-358b-xxxxxx.json.

I need to use matplotlib to draw graphs, but this requires a connection to a forwarded X11. Therefore, I use ssh -XY, and ensure that the DISPLAY variable is set correctly before running the kernel/console. I then plot things interactively using the %matplotlib magic, which uses the "TkAgg" backend.

Ssh disconnect and reconnect loses the X11 server and crashes python

First, when disconnecting from the server (Ctrl-D), the connection does not close until I hit Ctrl-C. I suspect this is killing the X11 connection initiated by Python. The jupyter kernel then throws the following error:

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server "localhost:11.0"
      after 8432 requests (8432 known processed) with 0 events remaining.

and usually I need to restart the kernel entirely, losing all variables. This is a major hurdle in my workflow. I have tried running the pyplot command plt.switch_backend("Agg") to stop using X11 before disconnecting, but it does not help.

Question

How to disconnect a jupyter kernel from X11 to avoid crashes between ssh sessions? Maybe a jupyter kernel code could be executed via jupyter-run?

Note that it is not possible to allow a local jupyter console to connect to the remote kernel because of network limitations on my work server (currently basic ssh-ing works, but not port forwarding).

0

There are 0 best solutions below