码迷,mamicode.com
首页 > 其他好文 > 详细

IPC-->PIPO

时间:2015-09-15 00:05:15      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

Programing python 4th page 228

技术分享
 1 """
 2 IPC
 3 http://www.cnblogs.com/BoyXiao/archive/2011/01/01/1923828.html
 4 """
 5 import os,time
 6 import threading
 7 
 8 def child(pipeout):
 9     zzz = 0
10     while True:
11         time.sleep(zzz)                                             # make parent wait
12         msg=(spam %03d \n % zzz).encode()                         # pipes are binary bytes
13         os.write(pipeout,msg)                                       # send to parent
14         zzz = (zzz+1)%5
15         
16 def parent(pipein):
17     while True:
18         line = os.read(pipein,32)                                   # blocks until data sent
19         print(parent %d got [%s]  at [%s]%(os.getpid(),line,time.ctime()))
20     
21 pipein,pipeout = os.pipe()
22 threading.Thread(target = child,args=(pipeout,)).start()
23 parent(pipein)
View Code

 

IPC-->PIPO

标签:

原文地址:http://www.cnblogs.com/lxk613/p/4808883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!