3

通常我可以用 Ctrl+C 打断东西,但有时当我使用线程时它不起作用——下面的例子。

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.sleep(100)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
K    eyboardInterrupt
>>> import Queue
>>> q = Queue.Queue(maxsize=3)
>>> q.put(0)
>>> q.put(1)
>>> q.put(2)
>>> q.put(3)
^C^C^C^C^C^C^C^C

^C^C^C

^C^C
^C
@*#()#@#@$!!!!!

编辑: 有没有办法回到口译员那里?到目前为止的解决方案完全杀死 python 和你现有的命名空间..

4

3 回答 3

3

Ctrl你可以用+杀死 Python 解释器\

这将发送一个SIGQUIT而不是SIGINT.

于 2011-09-06T06:58:15.587 回答
1

^C 失败的快速解决方法是先使用 ^Z 暂停所有线程的进程,然后将其终止。

当 ^C 失败时,这在 Linux 中适用于许多情况,正如我刚刚测试过的那样,它也可以在这里工作(在 Python v.2.6.5 上测试):

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Queue
>>> q = Queue.Queue(maxsize=3)
>>> q.put(0)
>>> q.put(1)
>>> q.put(2)
>>> [^C]
KeyboardInterrupt #does not kill the process
>>> [^Z - Suspends and exits to shell]
[1]+  Stopped                 python
#mdf:~$ kill -9 %%
[1]+  Killed                  python
于 2011-09-06T07:22:41.890 回答
0

一个懒惰的方法是打开另一个窗口。

做得到psPID。

kill杀死有问题的进程。

于 2011-09-06T13:47:35.560 回答