forked from Zjhao666/InnerStudioWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (34 loc) · 721 Bytes
/
test.py
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
30
31
32
33
34
35
36
import os
import time
from threading import Thread
def handle1(fd):
while True:
buf=os.read(fd,1024)
if buf:
print 'GET:%s'%buf
def handle2(fd):
while True:
buf=os.read(0,1024)
if buf:
print 'SEND:%s'%buf
os.write(fd,buf)
p2cr,p2cw=os.pipe()
c2pr,c2pw=os.pipe()
pid=os.fork()
if pid==0: # child
os.close(p2cw)
os.close(c2pr)
os.dup2(p2cr,0)
os.dup2(c2pw,1)
os.execvp('python',['python'])
os._exit(0)
else:
os.close(p2cr)
os.close(c2pw)
t=Thread(target=handle1,args=(c2pr,))
t.setDaemon(True)
t.start()
t=Thread(target=handle2,args=(p2cw,))
t.setDaemon(True)
t.start()
time.sleep(5)