[英]How to kill a running iPython process
I'm using iPython to control some other equipment connected to my Mac. 我正在使用iPython控制连接到Mac的其他设备。 Most of the time it runs fine, but sometimes I gave a wrong command to the equipment, iPython is just hanging forever since it's waiting for a response but won't get one, so I need a way to kill the iPython process. 在大多数情况下,它运行良好,但有时我向设备发出了错误的命令,由于它正在等待响应但无法获得响应,因此iPython永远挂起,因此我需要一种方法来终止iPython进程。 ctrl+c
doesn't do anything, it just prints a ^C
string on the screen. ctrl+c
不会执行任何操作,它只会在屏幕上打印一个^C
字符串。 ctrl+z
can get me out of iPython, but it doesn't seem to kill it, because when I restart iPython I can't re-establish the communication with the equipment. ctrl+z
可以使我脱离iPython,但似乎并不能杀死它,因为当我重新启动iPython时,无法与设备重新建立通信。 Eventually I had to restart my computer to get the two talking again. 最终,我不得不重新启动计算机,以使两者再次通话。
ctrl+z can get me out of iPython, but it doesn't seem to kill it, because when I restart iPython I can't re-establish the communication with the equipment. ctrl + z可以使我脱离iPython,但似乎并不能杀死它,因为当我重新启动iPython时,无法与设备重新建立通信。 Eventually I had to restart my computer to get the two talking again. 最终,我不得不重新启动计算机,以使两者再次通话。
Assuming you're using bash
(the default shell for OS X), the ^Z turns it into a suspended background job, and you can use job control to kill it: 假设您使用的是bash
(OS X的默认外壳),^ Z会将其变成挂起的后台作业,您可以使用作业控制将其杀死:
$ ipython
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
IPython 2.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]:
[2]+ Stopped ipython
$ kill %2
[2]+ Stopped ipython
$
[2]+ Terminated: 15 ipython
$
A couple of things to notice there: 那里需要注意的几件事:
[2]+ Stopped
; 看[2]+ Stopped
; that tells you that it's job 2, so you need kill %2
, not kill %1
. 告诉您这是工作2,因此您需要kill %2
而不是kill %1
。
2
for demonstration purposes.) (我特意在后台放置了另一项工作,使其成为2
用于演示目的。) jobs
command to list them all. 如果不确定要杀死哪个作业,请使用jobs
命令列出所有jobs
。 %ipython
, which refers to the first job whose name starts with ipython
. 或者,您可以使用%ipython
,这是指第一个名称以ipython
开头的ipython
。 %%
, which means the "current" job—if you haven't done anything since the ^Z
, that'll be ipython
, but if you've done a bunch of other stuff since then and aren't sure if you affected job control, be careful. 或%%
,这意味着“当前”工作-如果自^Z
以来ipython
任何事情,那将是ipython
,但如果ipython
您做了很多其他工作,并且不确定是否影响工作控制,要小心。 kill %2
kills the task immediately, bash
may not recognize that until the next prompt; 尽管kill %2
立即bash
了该任务,但bash
可能直到下一个提示时才意识到这一点; notice that I had to hit return
an extra time before seeing the Terminated
message. 请注意,在看到“已Terminated
消息之前,我必须打return
额外的时间。
wait
command. 在某些情况下,您需要使用wait
命令。 IPython
is very badly hung and not responding to signals properly, use kill -9 %2
. 如果IPython
严重挂起并且无法正确响应信号,请使用kill -9 %2
。 ^Z
by mistake and don't want to kill the job, use fg %2
instead of kill %2
to get back into IPython
. 如果您误击了^Z
并且不想终止该作业,请使用fg %2
而不是kill %2
返回IPython
。 IPython
run in the background while you do other things, use bg %2
instead of kill %2
. 如果要在执行其他操作时让IPython
在后台运行,请使用bg %2
而不是kill %2
。 (You can always fg
or kill
it later (or disown
it, or various other things—see the linked guide.) (您以后可以随时fg
或kill
它(或将其disown
或进行其他操作,请参阅链接的指南。) In the Terminal find out the process id using the "top" command. 在终端中,使用“ top”命令查找进程ID。 It is the PID column, and under the COMMAND column you will see IPython, or something similar. 它是PID列,在COMMAND列下,您将看到IPython或类似内容。 Them run kill -9 PID
他们跑kill -9 PID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.