我有一个创建子进程,并连接其到STDIN匿名管道的方法;这不起作用。它没有引发任何异常,子进程似乎永远不会读取数据。 (子进程是“zenity”可执行用于显示在GUI的进度条)连接到子标准输入到管
class Screen(object):
def __init__(self, display = ":0", bin = '/usr/bin/zenity'):
self.bin = bin
os.environ['DISPLAY'] = display
self.dis = display
def displayProgress(self, text, pulse = True, title = 'Progess'):
'''Method to represent the 'zenity --progress' command
'''
readp, writep = os.pipe()
reade, writee = os.pipe()
rfd = os.fdopen(readp, 'r')
wfd = os.fdopen(writep, 'w')
if pulse:
zenhandle = Popen([self.bin, '--progress',
'--title=%s' % title,
'--auto-close',
'--pulsate'],
stdin = rfd)
else:
zenhandle = Popen([self.bin, '--progress',
'--title=%s' % title,
'--auto-close'],
stdin = rfd)
self.progress = wfd
的想法是在调用该方法将是非阻塞的,我可以write()
到Screen.progress
和不得不写入的STDIN孩子(zenity)的过程。 (zenity绘制完成条形图,从STDIN读取值)
该框在屏幕上绘制,但Screen.progress.write('50')
从不更新栏。
我在做什么错?
编辑:
如果以交互方式运行,当我退出Python外壳,酒吧开始移动。 (脉冲)这意味着它只在python进程退出后才读取 - something。
你真的需要手动制作自己的管道吗?为什么不让子进程为你处理。例如'handle = subprocess.Popen('cat',stdin = subprocess.PIPE); handle.stdin.write('hello')' – Dunes 2011-06-07 21:45:29
这将起作用,从我查看子程序的代码示例中,我认为stdin是从args读取到communications()方法的。谢谢! – tMC 2011-06-07 21:51:46