path tmp pipe chunk_size 8192 fd os open path os O_RDONLY os O_NONBLOC

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
path = '/tmp/pipe'
chunk_size = 8192
fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK)
def do_something():
pass
def check_timer():
pass
def do_another():
pass
while True:
try:
output = os.read(fd, chunk_size)
except (OSError, IOError):
print "Чето поломалось"
if not output:
print 'pipe закрылся'
else:
print "Мои данные: ", output
do_something()
if check_timer():
do_another()