简体   繁体   中英

Python - I can't stop the program running

I am completely new to python. I have installed it on 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. I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail. Could anyone point me in the right direction.

Many thanks

I'd recommend to use IPython . It brings a matplotlib/pylab mode that handles all this for you. After you install IPython, you can start it with the pylab flag:

$ 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.

The documentation of matplotlib has a little more information on how all this works.

如果只是中断正在运行的程序,那么您是否尝试过CTRL-D?

Try this:

After all of your imports for pylab and what not.. add:

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.

Try catching KeyboardInterrupt like so:

try:
    show()
except KeyboardInterrupt:
    print "Shutting down."
    import sys
    sys.exit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM