result.wait() , timeout, . , kill -9 [pid], .
, , "" ready(). , , , ready() False, .
, , pid . ApplyResult pid, . - :
def test(identifier):
pid = os.getpid()
f = open("pids/" + str(pid), "w")
f.write(str(identifier))
f.close()
time.sleep(1000)
, ( jobs = []).
job = (identifier, pool.apply_async(test, (identifier,)))
jobs.append(job)
, , , ApplyResult pid.
, (pid):
def is_alive(pid):
return os.path.exists("/proc/" + str(pid))
for pid in os.listdir("pids"):
if is_alive(pid):
...
else:
...
pid-named . , identifier, jobs, , ApplyResult pid , ready(), .
.
r, w = os.pipe()
def child():
global r, w
data = ...
time.sleep(100)
os.close(r)
w = os.fdopen(w, "w")
w.write(data)
w.close()
.
def parent(child_pid):
global r, w
os.close(w)
r = os.fdopen(r)
data = r.read()
r.close()
status = os.waitpid(child_pid, 0)
if status == 0:
elif status == 9:
status data, , .
.
if __name__ == "__main__":
child_pid = os.fork()
if child_pid:
parent(child_pid)
else:
child()
Unix. . , - -Python 2.7 , .