Problem running python/matplotlib in background after ending ssh session

后端 未结 4 571
长发绾君心
长发绾君心 2020-12-24 07:50

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

相关标签:
4条回答
  • 2020-12-24 08:26

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

    0 讨论(0)
  • 2020-12-24 08:29

    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')
    
    0 讨论(0)
  • 2020-12-24 08:34

    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

    0 讨论(0)
  • 2020-12-24 08:42

    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.

    0 讨论(0)
提交回复
热议问题