[issue40860] Exception in multiprocessing/context.py under load
Arkady
report at bugs.python.org
Wed Jun 10 08:13:49 EDT 2020
Arkady <larytet at gmail.com> added the comment:
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)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40860>
_______________________________________
More information about the Python-bugs-list
mailing list