|
|
@ -15,7 +15,8 @@ from multiprocessing import Pool, Process
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import socket
|
|
|
|
from contextlib import closing
|
|
|
|
from contextlib import closing
|
|
|
|
import psutil
|
|
|
|
import time
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def launch_func(func, env_dict):
|
|
|
|
def launch_func(func, env_dict):
|
|
|
@ -25,18 +26,35 @@ def launch_func(func, env_dict):
|
|
|
|
return proc
|
|
|
|
return proc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def wait(procs, timeout=None):
|
|
|
|
def wait(procs, timeout=30):
|
|
|
|
# wait
|
|
|
|
error = False
|
|
|
|
decents = []
|
|
|
|
begin = time.time()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
alive = False
|
|
|
|
for p in procs:
|
|
|
|
for p in procs:
|
|
|
|
for child in psutil.Process(p.pid).children(recursive=True):
|
|
|
|
p.join(timeout=10)
|
|
|
|
decents.append(child)
|
|
|
|
if p.exitcode is None:
|
|
|
|
|
|
|
|
alive = True
|
|
|
|
gone, alive = psutil.wait_procs(decents, timeout=timeout)
|
|
|
|
continue
|
|
|
|
for p in alive:
|
|
|
|
elif p.exitcode != 0:
|
|
|
|
p.kill()
|
|
|
|
error = True
|
|
|
|
for p in gone:
|
|
|
|
break
|
|
|
|
if p.returncode != 0:
|
|
|
|
|
|
|
|
|
|
|
|
if not alive:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if error:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if timeout is not None and time.time() - begin >= timeout:
|
|
|
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for p in procs:
|
|
|
|
|
|
|
|
if p.is_alive():
|
|
|
|
|
|
|
|
p.terminate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if error:
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|