You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/03/13 21:22:36 UTC
[2/2] ambari git commit: AMBARI-20070. Agent heartbeat lost due to
subprocess.Popen race condition -- addendum for multiprocessing
AMBARI-20070. Agent heartbeat lost due to subprocess.Popen race condition -- addendum for multiprocessing
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7794d132
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7794d132
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7794d132
Branch: refs/heads/branch-2.5
Commit: 7794d1326f075bd1c7e8a3ce5a8eb62c48154d8a
Parents: 09fcf9b
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Sat Mar 11 19:13:16 2017 +0100
Committer: Attila Doroszlai <ad...@hortonworks.com>
Committed: Mon Mar 13 22:22:14 2017 +0100
----------------------------------------------------------------------
.../src/main/python/ambari_agent/main.py | 21 ++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/7794d132/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index bbed123..604b234 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -45,23 +45,32 @@ def fix_subprocess_racecondition():
def fix_subprocess_popen():
'''
- http://bugs.python.org/issue19809
+ Workaround for race condition in starting subprocesses concurrently from
+ multiple threads via the subprocess and multiprocessing modules.
+ See http://bugs.python.org/issue19809 for details and repro script.
'''
import os
import sys
if os.name == 'posix' and sys.version_info[0] < 3:
+ from multiprocessing import forking
import subprocess
import threading
- original_init = subprocess.Popen.__init__
- lock = threading.RLock()
+ sp_original_init = subprocess.Popen.__init__
+ mp_original_init = forking.Popen.__init__
+ lock = threading.RLock() # guards subprocess creation
- def locked_init(self, *a, **kw):
+ def sp_locked_init(self, *a, **kw):
with lock:
- original_init(self, *a, **kw)
+ sp_original_init(self, *a, **kw)
- subprocess.Popen.__init__ = locked_init
+ def mp_locked_init(self, *a, **kw):
+ with lock:
+ mp_original_init(self, *a, **kw)
+
+ subprocess.Popen.__init__ = sp_locked_init
+ forking.Popen.__init__ = mp_locked_init
fix_subprocess_popen()