57 import threading |
57 import threading |
58 import killdaemons as killmod |
58 import killdaemons as killmod |
59 import Queue as queue |
59 import Queue as queue |
60 |
60 |
61 processlock = threading.Lock() |
61 processlock = threading.Lock() |
|
62 waitlock = threading.Lock() |
|
63 |
|
64 def waitlocked(fn): |
|
65 def run(): |
|
66 waitlock.acquire() |
|
67 ret = fn() |
|
68 waitlock.release() |
|
69 return ret |
|
70 return run |
62 |
71 |
63 closefds = os.name == 'posix' |
72 closefds = os.name == 'posix' |
64 def Popen4(cmd, wd, timeout, env=None): |
73 def Popen4(cmd, wd, timeout, env=None): |
65 processlock.acquire() |
74 processlock.acquire() |
66 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env, |
75 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env, |
67 close_fds=closefds, |
76 close_fds=closefds, |
68 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
77 stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
69 stderr=subprocess.STDOUT) |
78 stderr=subprocess.STDOUT) |
|
79 p.wait = waitlocked(p.wait) |
|
80 p.poll = waitlocked(p.poll) |
70 processlock.release() |
81 processlock.release() |
71 |
82 |
72 p.fromchild = p.stdout |
83 p.fromchild = p.stdout |
73 p.tochild = p.stdin |
84 p.tochild = p.stdin |
74 p.childerr = p.stderr |
85 p.childerr = p.stderr |