[英]Python - I can't stop the program running
I am completely new to python. 我对python完全陌生。 I have installed it on windows.
我已经在Windows上安装了它。 I am having a problem, I write:
我有一个问题,我写道:
from pylab import*
subplot(111,projection="hammer")
show()
After this it will not let me do anything else and ctrl-c does not work. 在此之后,它将不允许我执行其他任何操作,并且ctrl-c无法正常工作。 I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail.
我在这里看过另一篇文章,尝试了ctrl-break,ctrl-z和其他各种方法都无济于事。 Could anyone point me in the right direction.
谁能指出我正确的方向。
Many thanks 非常感谢
I'd recommend to use IPython . 我建议使用IPython 。 It brings a matplotlib/pylab mode that handles all this for you.
它带来了一个matplotlib / pylab模式,可以为您处理所有这一切。 After you install IPython, you can start it with the
pylab
flag: 安装IPython之后,可以使用
pylab
标志启动它:
$ ipython -pylab
Then, in the interactive shell, you type your code: 然后,在交互式外壳中,键入代码:
In [1]: from pylab import*
In [2]: subplot(111,projection="hammer")
Out[2]: <matplotlib.axes.HammerAxesSubplot object at 0x2241050>
In [3]:
IPython automatically shows the plot using a separate thread and returns control to the interactive shell. IPython使用一个单独的线程自动显示该图,并将控件返回到交互式外壳。
The documentation of matplotlib has a little more information on how all this works. matplotlib的文档提供了更多有关所有工作原理的信息。
如果只是中断正在运行的程序,那么您是否尝试过CTRL-D?
Try this: 尝试这个:
After all of your imports for pylab and what not.. add: 在所有导入pylab之后,什么都没有..添加:
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
This will cause CTRL-C to not be caught by anything in your program, which should then cause it to kill the program. 这将导致CTRL-C不会被程序中的任何内容捕获,这将导致其终止程序。
Try catching KeyboardInterrupt
like so: 尝试像这样捕获
KeyboardInterrupt
:
try:
show()
except KeyboardInterrupt:
print "Shutting down."
import sys
sys.exit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.