问题描述
我要VPN,然后从家里ssh来我的工作服务器,并希望在后台运行一个python脚本,然后注销的SSH会话。我的剧本提出了一些直方图使用matplotlib,只要我保持连接打开一切都很好,但如果我登出我保持我的脚本创建的日志文件收到错误消息。
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 using matplotlib, and as long as I keep the connection open everything is fine, but if I log out I keep getting an error message in the log file I created for the script.
File "/Home/eud/jmcohen/.local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 2058, in loglog
ax = gca()
File "/Home/eud/jmcohen/.local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 582, in gca
ax = gcf().gca(**kwargs)
File "/Home/eud/jmcohen/.local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 276, in gcf
return figure()
File "/Home/eud/jmcohen/.local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 254, in figure
**kwargs)
File "/Home/eud/jmcohen/.local/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 90, in new_figure_manager
window = Tk.Tk()
File "/Home/eud/jmcohen/.local/lib/python2.5/lib-tk/Tkinter.py", line 1647, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:10.0"
我假设它不知道在哪里创建我想,因为我结束我的X11 SSH会话的数字。如果我在脚本运行记录我我看不到任何数字雨后春笋般冒出来(虽然那是因为我没有在我的脚本演出()命令做),我认为Python使用Tkinter的显示数字。我要创建的数字的方式是,
I'm assuming that it doesn't know where to create the figures I want since I close my X11 ssh session. If I'm logged in while the script is running I don't see any figures popping up (although that's because I don't have the show() command in my script), and I thought that python uses tkinter to display figures. The way that I'm creating the figures is,
loglog()
hist(list,x)
ylabel('y')
xlabel('x')
savefig('%s_hist.ps' %source.name)
close()
该脚本需要一些初始投入,所以我它运行在后台的办法就是
The script requires some initial input, so the way I'm running it in the background is
python scriptToRun.py << start>& logfile.log&
有没有解决的办法,或者说我只是要留SSH方式登录我的机器?
Is there a way around this, or do I just have to stay ssh'd into my machine?
感谢。
推荐答案
它看起来像你在交互模式在默认情况下运行,因此matplotlib希望首先绘制一切到屏幕上,这当然它不能做。
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.
尝试把
ioff()
在你的脚本的顶部,使得后端的变化而
at the top of your script, along with making the backend change.
引用:http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.ioff
这篇关于问题运行蟒蛇/ matplotlib在后台结束SSH会话后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!