Python可以杀死继续运行的子进程吗? [英] Can Python kill a child process that keeps on running?

查看:98
本文介绍了Python可以杀死继续运行的子进程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们用Popen生成子进程。我正在考虑一个

可执行文件,就像编译的C程序一样。

假设它应该运行一分钟,但它只是继续运行

并继续。 Python有没有办法杀死它?


这不是假设的;我现在正在这样做,并且它的工作非常好,但是我希望能够处理这种连续状态。我是

使用Windows 2000,但我希望我的程序可以移植到linux。


谢谢


Mitchell Timin


-

我很自豪 http://ANNEvolve.sourceforge.net 。如果你想为ANNEvolve写软件,b $ b或文章,或做测试或研​​究,请告诉我。


人类可能知道我的电子邮件地址是:(但删除3位数字)

zenguy at shaw666 dot ca

解决方案

我。我写道:

假设我们用Popen生成一个子进程。我正在考虑一个
可执行文件,就像编译的C程序一样。
假设它应该运行一分钟,但它只是继续运行
然后继续运行。 Python有没有办法杀死它?

这不是假设的;我现在正在这样做,而且它的工作非常好,但我希望能够处理这种连续状态。我正在使用Windows 2000,但我希望我的程序可以移植到linux。




在linux上它很容易做到,只需设置报警信号。在windows上

使用python.org

发布你不能做到这一点并不是那么微不足道,你需要使用win32在低级别的C API中查找

扩展名或ctypes。 AFAIK扭曲包< http://twistedmatrix.com>

有一些代码可以帮助你。另请参阅buildbot来源

< http://buildbot.sf.net>使用扭曲。 Buildbot与你有相同的问题,它需要杀死逃跑或无响应

进程。

<塞尔·奥尔洛夫写道:

I.我自己写道:

假设我们用Popen生成一个子进程。我正在考虑一个
可执行文件,就像编译的C程序一样。
假设它应该运行一分钟,但它只是继续运行
然后继续运行。 Python有没有办法杀死它?

这不是假设的;我现在正在这样做,而且它的工作非常好,但我希望能够处理这种连续状态。我正在使用Windows 2000,但我希望我的程序可以移植到linux。



在linux上它很容易做到,只需设置报警信号。在windows上
使用python.org
发布你不能做到这一点并不是那么简单,你需要使用win32
扩展或ctypes来寻找低级别的C API。 AFAIK扭曲包< http://twistedmatrix.com>
有一些代码可以帮助您。另请参阅buildbot来源
< http://buildbot.sf.net>使用扭曲。 Buildbot和你有同样的问题,它需要杀掉逃跑或无响应的过程。



这是坏消息。不管怎么说,还是要谢谢你;坏消息比没有新闻好。


Mitchell Timin


-

我很自豪 http://ANNEvolve.sourceforge.net 。如果你想为ANNEvolve写软件,b $ b或文章,或做测试或研​​究,请告诉我。


人类可能知道我的电子邮件地址是:(但删除3位数字)

zenguy at shaw666 dot ca


I。我自己写道:

Serge Orlov写道:

我。我自己写道:

假设我们用Popen生成一个子进程。我正在考虑一个
可执行文件,就像编译的C程序一样。
假设它应该运行一分钟,但它只是继续运行
然后继续运行。 Python有没有办法杀死它?

这不是假设的;我现在正在这样做,而且它的工作非常好,但我希望能够处理这种连续状态。我正在使用Windows 2000,但我希望我的程序可以移植到linux。



在linux上它很容易做到,只需设置报警信号。在windows上
使用python.org
发布你不能做到这一点并不是那么简单,你需要使用win32
扩展或ctypes来寻找低级别的C API。 AFAIK扭曲包< http://twistedmatrix.com>
有一些代码可以帮助您。另请参阅buildbot来源
< http://buildbot.sf.net>使用扭曲。 Buildbot和你有同样的问题,它需要杀掉逃跑或无响应的过程。



这是坏消息。不管怎么说,还是要谢谢你;坏消息胜过没有新闻。



但是,请注意,taht ctypes计划是2.5

发行版的一部分,所以虽然可能没有是一个独立于平台的方式来实现你的目标,你可以在没有外部

扩展的情况下实现你的目标。


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

爱我,爱我的博客 http://holdenweb.blogspot.com

最近的Ramblings http://del.icio.us/steve.holden


Suppose we spawn a child process with Popen. I''m thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?

This is not hypothetical; I''m doing it now, and it''s working pretty
well, but I would like to be able to handle this run-on condition. I''m
using Windows 2000, but I want my program to be portable to linux.

Thanks

Mitchell Timin

--
I''m proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca

解决方案

I. Myself wrote:

Suppose we spawn a child process with Popen. I''m thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?

This is not hypothetical; I''m doing it now, and it''s working pretty
well, but I would like to be able to handle this run-on condition. I''m
using Windows 2000, but I want my program to be portable to linux.



On linux it''s pretty easy to do, just setup alarm signal. On windows
it''s not so trivial to the point you cannot do it using python.org
distribution, you will need to poke in low level C API using win32
extensions or ctypes. AFAIK twisted package <http://twistedmatrix.com>
has some code to help you. Also take a look at buildbot sources
<http://buildbot.sf.net> that uses twisted. Buildbot has the same
problem as you have, it needs to kill run away or non-responding
processes.


Serge Orlov wrote:

I. Myself wrote:

Suppose we spawn a child process with Popen. I''m thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?

This is not hypothetical; I''m doing it now, and it''s working pretty
well, but I would like to be able to handle this run-on condition. I''m
using Windows 2000, but I want my program to be portable to linux.



On linux it''s pretty easy to do, just setup alarm signal. On windows
it''s not so trivial to the point you cannot do it using python.org
distribution, you will need to poke in low level C API using win32
extensions or ctypes. AFAIK twisted package <http://twistedmatrix.com>
has some code to help you. Also take a look at buildbot sources
<http://buildbot.sf.net> that uses twisted. Buildbot has the same
problem as you have, it needs to kill run away or non-responding
processes.


That is bad news. Thanks anyway; bad news is better than no news.

Mitchell Timin

--
I''m proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


I. Myself wrote:

Serge Orlov wrote:

I. Myself wrote:

Suppose we spawn a child process with Popen. I''m thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?

This is not hypothetical; I''m doing it now, and it''s working pretty
well, but I would like to be able to handle this run-on condition. I''m
using Windows 2000, but I want my program to be portable to linux.



On linux it''s pretty easy to do, just setup alarm signal. On windows
it''s not so trivial to the point you cannot do it using python.org
distribution, you will need to poke in low level C API using win32
extensions or ctypes. AFAIK twisted package <http://twistedmatrix.com>
has some code to help you. Also take a look at buildbot sources
<http://buildbot.sf.net> that uses twisted. Buildbot has the same
problem as you have, it needs to kill run away or non-responding
processes.



That is bad news. Thanks anyway; bad news is better than no news.


Note, however, taht ctypes is planned to be a part of the 2.5
distribution, so while there may not be a platform-independent way to
achieve your goals you will at leats be able to do so without external
extensions.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden


这篇关于Python可以杀死继续运行的子进程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆