Message371184
A workaround is to synchronize the call to Process.start()
diff --git a/main.py b/main.py
index d09dc53..49d68f0 100644
--- a/main.py
+++ b/main.py
@@ -26,17 +26,24 @@ def load_cpu(deadline):
while time.time() - start < 0.2*deadline:
math.pow(random.randint(0, 1), random.randint(0, 1))
+def join_process(job, timeout):
+ time_start = time.time()
+ while time.time()-time_start < timeout and job.is_alive():
+ time.sleep(0.1 * timeout)
+ continue
+
job_counter = 0
+lock = threading.Lock()
def spawn_job(deadline):
'''
Creat a new Process, call join(), process errors
'''
global job_counter
time_start = time.time()
- job = multiprocessing.Process(target=load_cpu, args=(deadline, ))
- job.start()
- # timeout=None in the call to join() solves the problem
- job.join(deadline)
+ with lock:
+ job = multiprocessing.Process(target=load_cpu, args=(deadline, ))
+ job.start()
+ join_process(job, deadline) |
|
Date |
User |
Action |
Args |
2020-06-10 12:13:49 | Arkady M | set | recipients:
+ Arkady M, pitrou, davin |
2020-06-10 12:13:49 | Arkady M | set | messageid: <1591791229.94.0.657635762104.issue40860@roundup.psfhosted.org> |
2020-06-10 12:13:49 | Arkady M | link | issue40860 messages |
2020-06-10 12:13:49 | Arkady M | create | |
|