You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exception in multiprocessing/context.py under load #85037
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-10-20.11:16:26.863>created_at=<Date2020-06-04.03:06:13.020>labels= ['3.7', 'type-crash']
title='Exception in multiprocessing/context.py under load'updated_at=<Date2020-10-20.11:16:26.862>user='https://bugs.python.org/ArkadyM'
I am running an HTTP server (socketserver.ThreadingMixIn, http.server.HTTPServer) in a Docker container (FROM ubuntu:19.10)
Occasionally I get an exception:
Exception happened during processing of request from ('172.17.0.1', 35756)
Traceback (most recent call last):
File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_threadself.finish_request(request, client_address)
File "/usr/lib/python3.7/socketserver.py", line 360, in finish_requestself.RequestHandlerClass(request, client_address, self)
File "service.py", line 221, in __init__super(UrlExtractorServer, self).__init__(*args, **kwargs)
File "/usr/lib/python3.7/socketserver.py", line 720, in __init__self.handle()
File "/usr/lib/python3.7/http/server.py", line 426, in handleself.handle_one_request()
File "/usr/lib/python3.7/http/server.py", line 414, in handle_one_request
method()
File "service.py", line 488, in do_POSTself._post_extract(url)
File "service.py", line 459, in _post_extract
extracted_links, err_msg =self._extract_links(transaction_id, attachment_id, zip_password, data)
File "service.py", line 403, in _extract_links
error, results = call_timeout(process_deadline, extractor.extract_links_binary_multiprocess, args=data)
File "service.py", line 175, in call_timeout
manager = multiprocessing.Manager()
File "/usr/lib/python3.7/multiprocessing/context.py", line 56, in Manager
m.start()
File "/usr/lib/python3.7/multiprocessing/managers.py", line 563, in startself._process.start()
File "/usr/lib/python3.7/multiprocessing/process.py", line 111, in start
_cleanup()
File "/usr/lib/python3.7/multiprocessing/process.py", line 56, in _cleanupif p._popen.poll() isnotNone:
AttributeError: 'NoneType' object has no attribute 'poll'
I am in the process of preparingof of a reasonably simple piece of code demonstrating the problem.
Meanwhile the following can be important. In the code below I ma getting the elapse < timeout (20 times from 70K). In all case psutil.Process() returned psutil.NoSuchProcess
Update. I have reproduced the problem in the code not calling Process.join() at all. It require more time and more load, but eventually Process.start() crashes.
You can see that join and start both modify the global, non thread safe _children set. I'm guessing this is where you're seeing interference between threads.
I'm not sure a lock on start is enough - I think you need to get the lock for the join_process(job, deadline) call as well, because join can modify _children too. (Or, alternatively, manage all processes from a single thread.)
Activity
ArkadyM commentedon Jun 4, 2020
I am running an HTTP server (socketserver.ThreadingMixIn, http.server.HTTPServer) in a Docker container (FROM ubuntu:19.10)
Occasionally I get an exception:
Exception happened during processing of request from ('172.17.0.1', 35756) Traceback (most recent call last): File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "service.py", line 221, in __init__ super(UrlExtractorServer, self).__init__(*args, **kwargs) File "/usr/lib/python3.7/socketserver.py", line 720, in __init__ self.handle() File "/usr/lib/python3.7/http/server.py", line 426, in handle self.handle_one_request() File "/usr/lib/python3.7/http/server.py", line 414, in handle_one_request method() File "service.py", line 488, in do_POST self._post_extract(url) File "service.py", line 459, in _post_extract extracted_links, err_msg = self._extract_links(transaction_id, attachment_id, zip_password, data) File "service.py", line 403, in _extract_links error, results = call_timeout(process_deadline, extractor.extract_links_binary_multiprocess, args=data) File "service.py", line 175, in call_timeout manager = multiprocessing.Manager() File "/usr/lib/python3.7/multiprocessing/context.py", line 56, in Manager m.start() File "/usr/lib/python3.7/multiprocessing/managers.py", line 563, in start self._process.start() File "/usr/lib/python3.7/multiprocessing/process.py", line 111, in start _cleanup() File "/usr/lib/python3.7/multiprocessing/process.py", line 56, in _cleanup if p._popen.poll() is not None: AttributeError: 'NoneType' object has no attribute 'poll'I am in the process of preparingof of a reasonably simple piece of code demonstrating the problem.
Meanwhile the following can be important. In the code below I ma getting the elapse < timeout (20 times from 70K). In all case psutil.Process() returned psutil.NoSuchProcess
ArkadyM commentedon Jun 4, 2020
This code reproduces the problem https://github.com/larytet-py/multiprocess
I assume that my use of join() is not correct.
ArkadyM commentedon Jun 4, 2020
The problem is likely in the call to multiprocessing.Process.join() with timeout. If I use timeout=None the code works.
ArkadyM commentedon Jun 7, 2020
Is there any news about?
This 50 lines sample reproduces the problem https://github.com/larytet-py/multiprocess
Please let me know if more information is needed.
ArkadyM commentedon Jun 10, 2020
Update. I have reproduced the problem in the code not calling Process.join() at all. It require more time and more load, but eventually Process.start() crashes.
Posted a question on https://stackoverflow.com/questions/62276345/call-to-pythons-mutliprocessing-process-join-fails
The problem reproduces in MacOS as well.
ArkadyM commentedon Jun 10, 2020
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))
ArkadyM commentedon Jun 19, 2020
There is a memory leak every time call to join() fails (is https://bugs.python.org/issue37788 relevant?)
iritkatriel commentedon Aug 9, 2020
The source code for the Process class is here: https://github.com/python/cpython/blob/master/Lib/multiprocessing/process.py
You can see that join and start both modify the global, non thread safe _children set. I'm guessing this is where you're seeing interference between threads.
I'm not sure a lock on start is enough - I think you need to get the lock for the join_process(job, deadline) call as well, because join can modify _children too. (Or, alternatively, manage all processes from a single thread.)
ArkadyM commentedon Aug 10, 2020
I have switched to os.fork() I am doing something like this https://gist.github.com/larytet/3ca9f9a32b1dc089a24cb7011455141f
iritkatriel commentedon Aug 10, 2020
There is an open ticket to improve documentation of thread safety of the multiprocessing module module: https://bugs.python.org/issue40815
Is there anything remaining to do on this ticket?
ArkadyM commentedon Aug 10, 2020
"documentation of thread safety"
I find it surprising that a module called "multiprocessing" has not a thread safe API.
If this is inevitable, I guess that's the life. I expect nothing less that a bold bright red font at the top of the document page.
Protecting a call to join() with a mutex would impact latency of the API: the slowest subprocess can win the race.
iritkatriel commentedon Aug 13, 2020
I agree that it would be better not to lock join, and instead manage each process from one thread.
I think this ticket can be closed as a duplicate of bpo-40815.
Lock operations around Process objects
Lock operations around Process objects