[Python 2.4 / 2.5]子进程模块非常缺乏? [英] [Python 2.4/2.5] subprocess module is sorely deficient?

查看:45
本文介绍了[Python 2.4 / 2.5]子进程模块非常缺乏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




很抱歉在列表中以负面消息开头,但我觉得Python

子流程模块非常缺乏,因为它缺少一种机制:


1.创建非阻塞管道,可以在一个单独的线程中读取(我是
目前正在Tkinter中编写一个mencoder GUI并且需要一个完整的过程

处理程序来控制命令行并在

文本框中显示进度)


2.以独立于平台的方式杀死子流程(即没有第三方

模块,没有黑客攻击)。


有没有办法使用非使用子进程阻止Popen对象? 2 -

有没有办法以独立于平台的方式以纯粹的Pythonic方式杀死子进程?我最初认为这个问题很简单,

但是在过去的几天里我一直在努力寻找任何

的答案。我已经浏览了几十个邮件列表档案,以找到一个

的解决方案。不幸的是,这些解决方案似乎都不符合我的需求。


我唯一的解决方案似乎是为最终用户提供mencoder命令行

并让它们执行它是手动完成的,但这似乎是一个相当的弱b解决方案。


-

问候,
V. Harishankar

http://hari.literaryforums。组织
http://harishankar.org

推荐答案

4月22日12:52,Harishankar< v.harishan ... @ gmail.comwrote:
On 22 Apr, 12:52, Harishankar <v.harishan...@gmail.comwrote:

>

有没有办法使用子进程使用非阻塞Popen对象? 2 -

有没有办法以独立于平台的方式以纯粹的Pythonic方式杀死子进程?我最初认为这个问题很简单,

但是在过去的几天里我一直在努力寻找任何

的答案。我已经浏览了几十个邮件列表档案,以找到一个

的解决方案。不幸的是,这些解决方案似乎都不符合我的需求。
>
Is there any way to use non-blocking Popen objects using subprocess? and 2 -
is there a way to kill the subprocess in a platform independent manner in a
purely Pythonic way? I thought initially that this problem is simple enough,
but over the last couple of days I''ve been really struggling to find any
answer. I''ve been through dozens of mailing list archives in to find a
solution. Unfortunately none of the solutions seem to fit my needs.



如果你想要一些关于使用带有非阻塞I / O的子进程的提示,你可能会在我的jailtools和pprocess项目中找到一些:

http://www.python.org/pypi / jailtools
http://www.python.org/ pypi / pprocess


付出了一些努力(因为我不记得是否可以在Windows上使用民意调查库

功能,所以你可能不得不使用选择

函数代替)。如果他们使用缓冲的I / O,可能很难维持非阻塞和流程的通信,而且我唯一可以使基于Python的子流程在jailtools中工作的方式是b
使用无缓冲选项(-u)调用

If you want some hints about using subprocesses with non-blocking I/O,
you might find some in my jailtools and pprocess projects:

http://www.python.org/pypi/jailtools
http://www.python.org/pypi/pprocess

Although these projects involve things which are not exactly cross-
platform, the communications mechanisms should be portable, perhaps
with a bit of effort (since I don''t recall whether the poll library
function is available on Windows, so you might have to use the select
function instead). It can be awkward sustaining non-blocking
communications with processes if they use buffered I/O, and the only
way I could make Python-based subprocesses work in jailtools was to
invoke them with the unbuffered option (-u).


我唯一的解决方案似乎是为最终用户提供mencoder命令行

并让他们手动执行它并完成它但这似乎是一个相当无比的b $ b b弱解决方案。
My only solution seems to be to offer the end user the mencoder command line
and make them execute it manually and be done with it but that seems a rather
weak solution.



子流程模块可能是对popen2模块的改进,以及各种os模块功能,但它仍然相当神秘。


Paul

The subprocess module may be an improvement over the popen2 module and
various os module functions, but it''s still rather arcane.

Paul


2008年4月22日星期二17:06:26 Paul Boddie写道:
On Tuesday 22 Apr 2008 17:06:26 Paul Boddie wrote:

4月22日,12:52,Harishankar< v.harishan ... @ gmail.comwrote:
On 22 Apr, 12:52, Harishankar <v.harishan...@gmail.comwrote:

有什么办法吗?使用子进程使用非阻塞Popen对象?并且

2 - 有没有办法以纯粹的Pythonic方式以独立于平台的方式杀死子进程?我最初认为这个问题很简单,但在过去的几天里,我真的很难找到任何答案。我已经通过几十个邮件列表

档案来寻找解决方案。不幸的是,没有一个解决方案可以满足我的需求。
Is there any way to use non-blocking Popen objects using subprocess? and
2 - is there a way to kill the subprocess in a platform independent
manner in a purely Pythonic way? I thought initially that this problem is
simple enough, but over the last couple of days I''ve been really
struggling to find any answer. I''ve been through dozens of mailing list
archives in to find a solution. Unfortunately none of the solutions seem
to fit my needs.



如果你想要一些关于使用带有非阻塞I / O的子进程的提示,你可能会在我的jailtools和pprocess项目中找到一些:

http://www.python.org/pypi / jailtools
http://www.python.org/ pypi / pprocess



谢谢。我会看看那些。实际上我觉得这样的机制

将来应该内置到Python中。

Thank you. I will take a look at those. Actually I feel a mechanism like this
should be built-in to Python in the future.


虽然这些项目涉及的事情不是完全交叉 -

平台,通讯机制应该是便携式的,也许需要花费一点力气(因为我不记得是否民意调查库
Windows上提供
功能,因此您可能需要使用选择

功能。如果他们使用缓冲的I / O,可能很难维持非阻塞和流程的通信,而且我唯一可以使基于Python的子流程在jailtools中工作的方式是b
使用无缓冲选项(-u)调用

Although these projects involve things which are not exactly cross-
platform, the communications mechanisms should be portable, perhaps
with a bit of effort (since I don''t recall whether the poll library
function is available on Windows, so you might have to use the select
function instead). It can be awkward sustaining non-blocking
communications with processes if they use buffered I/O, and the only
way I could make Python-based subprocesses work in jailtools was to
invoke them with the unbuffered option (-u).

我唯一的解决方案似乎是为最终用户提供mencoder命令

行并让他们手动执行它并完成它但这似乎是一个相当弱的解决方案。
My only solution seems to be to offer the end user the mencoder command
line and make them execute it manually and be done with it but that seems
a rather weak solution.



子流程模块可能是对popen2模块的改进,以及各种os模块功能,但它仍然相当神秘。


The subprocess module may be an improvement over the popen2 module and
various os module functions, but it''s still rather arcane.



是的。我很确定必须有一个优雅的子流程解决方案

处理/管理。问题是我已经在这里呆了三天而且我已经非常闷闷不乐地试图通过大量的文档来填充这些内容;-)


-

问候,

V. Harishankar

http://hari.literaryforums.org
http://harishankar.org


4月22日下午12:52,Harishankar< v.harishan ... @ gmail.comwrote:
On Apr 22, 12:52 pm, Harishankar <v.harishan...@gmail.comwrote:




很抱歉从列表中的否定音符开始,但我觉得Python

子流程模块非常缺乏,因为它缺乏以下机制:


1.创建可以在单独的线程中读取的非阻塞管道(我是

目前正在Tkinter中编写一个mencoder GUI,需要一个完整的流程

处理程序来控制命令行和dis在

文本框中播放进度)
Hi,

Sorry to start off on a negative note in the list, but I feel that the Python
subprocess module is sorely deficient because it lacks a mechanism to:

1. Create non-blocking pipes which can be read in a separate thread (I am
currently writing a mencoder GUI in Tkinter and need a full fledged process
handler to control the command line and to display the progress in a
text-box)



我建议你查看一下: http://aspn.activestate.com/ASPN/Coo.../Recipe/440554


干杯,

Nicola Musatti

I suggest you check out this: http://aspn.activestate.com/ASPN/Coo.../Recipe/440554

Cheers,
Nicola Musatti


这篇关于[Python 2.4 / 2.5]子进程模块非常缺乏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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