Skip to content Skip to sidebar Skip to footer

Problem Running Python/matplotlib In Background After Ending Ssh Session

I have to VPN and then ssh from home to my work server and want to run a python script in the background, then log out of the ssh session. My script makes several histogram plots u

Solution 1:

I believe your matplotlib backend requires X11. Look in your matplotlibrc file to determine what your default is (from the error, I'm betting TkAgg). To run without X11, use the Agg backend. Either set it globally in the matplotlibrc file or on a script by script by adding this to the python program:

import matplotlib
matplotlib.use('Agg')

Solution 2:

It looks like you're running in interactive mode by default, so matplotlib wants to plot everything to the screen first, which of course it can't do.

Try putting

ioff()

at the top of your script, along with making the backend change.

reference: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.ioff

Solution 3:

Sorry if this is a stupid answer, but if you're just running a console session, would 'screen' not suffice? Detachable sessions, etc.

Solution 4:

If you are running on a *nix OS the problem is your session is terminated and all processes requiring a session are also terminated when you disconnect. More specifically all your processes are sent a SIGHUP (signal hang-up). The default handling of SITHUP is to terminate the process. If you want you script to continue it needs to ignore the signal. The easiest way to do that assuming you start your script via the command line it to run it using the nohup command:

nohup python scriptToRun.py << start>& logfile.log&

nohup normally sends standard out and standard error to the file nohup.out in the current directory. Since you're redirecting already output nohup.out will not be created.

Post a Comment for "Problem Running Python/matplotlib In Background After Ending Ssh Session"