2005年07月25日 星期一 10:10
你们发什么神精,你们聊天的邮件干什么发到我的邮箱上. > 我也开始Py了 > > > > ======= 2005-07-24 22:57:57 您在来信中写道:======= > > >当Collector接收到'exit'退出时,Receiver仍然会向Collector发送'exit'字符串,所 > >以会Broken pipe。 > > > >以下的代码在Windows和Debian上都没有问题。 > >改动了Receiver > > > ># receiver.py (the main program) > >from subprocess import Popen, PIPE > > > >def main(): > > p = Popen(['python', 'collector.py'], stdout=PIPE, stdin=PIPE) > > keep_going = False > > count = 0 > > for line in p.stdout: > > data = line.strip() > > print 'Receiver: ' + line > > # process(data) > > count += 1 > > if count >= 1000: > > if keep_going == False: > > print >> p.stdin, 'exit' > > keep_going = True > > print 'waiting subprocess exit' > > p.wait() > > > >if __name__ == '__main__': > > main() > >#end of receiver.py > > > >__ > >Best Regards, > > > >Kebo Wang > > > > > >_______________________________________________ > >python-chinese list > >python-chinese at lists.python.cn > >http://python.cn/mailman/listinfo/python-chinese > > = = = = = = = = = = = = = = = = = = = = > > > 致 > 礼! > > > cn-poper > cn-poper at 126.com > 2005-07-25 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050725/6cc69851/attachment.html
2005年07月25日 星期一 10:29
管理员直接把他删除吧,他不知道自己怎么加进来的,也不知道这里是做什么的。 寒号鸟 wrote: > 你们发什么神精,你们聊天的邮件干什么发到我的邮箱上.
2005年07月25日 星期一 14:10
我感觉好像只有一个进程结束了才会去读写另一个进程的stdin和stdout。
下面是我写的两个程序,我也没理出头绪,写出来给大家参考一下
################################################################
# caller.py
################################################################
from subprocess import Popen, PIPE
from time import sleep
sp = Popen(["python", 'callee.py'], stdin = PIPE)
sleep(2)
print "\n\nwriting exit \n\n"
sp.stdin.write("exit")
sp.stdin.flush()
sleep(4)
print "\n\nwriting exit\n\n"
sp.stdin.write('exit')
################################################################
# callee.py
################################################################
import sys, string, random
import threading, time
class Main(object) :
def __init__(self) :
self.flag = True
self.thread = threading.Thread(target = self.work)
self.thread.setDaemon(1)
self.thread2 = threading.Thread(target = self.stop)
self.thread2.setDaemon(1)
self.thread.start()
self.thread2.start()
self.thread.join()
self.thread2.join()
def stop(self) :
s = time.time()
while 1 :
if time.time() - s > 10 :
print "Timeout!!"
self.flag = False
return
try :
t = sys.stdin.read()
self.flag = False
return
except :
time.sleep(0.3)
def work(self) :
while self.flag :
num = random.choice(range(8, 20))
s = string.letters + string.digits + string.punctuation
result = ""
for i in range(num) :
result += random.choice(s)
result += "\n"
sys.stdout.write(result)
sys.stdout.flush()
time.sleep(0.5)
if __name__ == "__main__" :
start = time.time()
Main()
print "\n\n"
print time.time() - start
往callee的stdin里面写东西根本没用。只有caller结束,callee才会收到东西。用flush都没用
On 7/24/05, cpunion <cpunion at 263.net> wrote:
> 管理员直接把他删除吧,他不知道自己怎么加进来的,也不知道这里是做什么的。
>
> 寒号鸟 wrote:
> > 你们发什么神精,你们聊天的邮件干什么发到我的邮箱上.
>
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
Zeuux © 2025
京ICP备05028076号