我有一个创建子进程并将其连接到匿名管道的方法,该方法不起作用。它不会引发任何异常,子进程似乎从未读取过数据。(子流程是用于在GUI中显示进度条的“zenity”可执行文件)
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进程退出之后读一些东西。
发布于 2011-06-07 18:35:30
您可能需要刷新文件缓冲区。试着在每次写完后执行self.progress.flush()。
https://stackoverflow.com/questions/6269886
复制相似问题