You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2015/06/16 21:42:55 UTC
ambari git commit: AMBARI-11956. HBase Master stop is hanging when
enabling security (Ivan Kozlov via smohanty)
Repository: ambari
Updated Branches:
refs/heads/trunk 8d98d9307 -> 5e2e50533
AMBARI-11956. HBase Master stop is hanging when enabling security (Ivan Kozlov via smohanty)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5e2e5053
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5e2e5053
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5e2e5053
Branch: refs/heads/trunk
Commit: 5e2e50533add8afe3a8b9e619372bc4e20cbab47
Parents: 8d98d93
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Tue Jun 16 12:37:03 2015 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Tue Jun 16 12:37:03 2015 -0700
----------------------------------------------------------------------
.../python/resource_management/core/shell.py | 42 +++++++++++++-------
1 file changed, 27 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5e2e5053/ambari-common/src/main/python/resource_management/core/shell.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/shell.py b/ambari-common/src/main/python/resource_management/core/shell.py
index 75b5fcf..75d4e56 100644
--- a/ambari-common/src/main/python/resource_management/core/shell.py
+++ b/ambari-common/src/main/python/resource_management/core/shell.py
@@ -212,9 +212,9 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE
preexec_fn=preexec_fn)
if timeout:
- timeout_happened=False
- start = time.time()
- end = start+timeout
+ timeout_event = threading.Event()
+ t = threading.Timer( timeout, _on_timeout, [proc, timeout_event] )
+ t.start()
if not wait_for_finish:
return proc
@@ -235,11 +235,13 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE
all_output = ""
while read_set:
- if timeout and time.time()> end:
- timeout_happened=True
- proc.kill()
+
+ is_proccess_running = (proc.poll() == None)
+ ready, _, _ = select.select(read_set, [], [], 1)
+
+ if not is_proccess_running and not ready:
break
- ready, _, _ = select.select(read_set, [], [])
+
for out_fd in read_set:
if out_fd in ready:
line = os.read(out_fd.fileno(), 1024)
@@ -247,6 +249,7 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE
if not line:
read_set = copy.copy(read_set)
read_set.remove(out_fd)
+ out_fd.close()
continue
fd_to_string[out_fd] += line
@@ -263,12 +266,7 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE
_print(line)
# Wait for process to terminate
- while proc.poll() == None:
- if timeout and time.time()> end:
- timeout_happened=True
- proc.kill()
- break
- time.sleep(1)
+ proc.wait()
finally:
for fp in files_to_close:
@@ -279,7 +277,10 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE
all_output = all_output.strip('\n')
if timeout:
- if timeout_happened:
+ if not timeout_event.is_set():
+ t.cancel()
+ # timeout occurred
+ else:
err_msg = ("Execution of '%s' was killed due timeout after %d seconds") % (command, timeout)
raise ExecuteTimeoutException(err_msg)
@@ -360,4 +361,15 @@ def string_cmd_from_args_list(command, auto_escape=True):
def _print(line):
sys.stdout.write(line)
- sys.stdout.flush()
\ No newline at end of file
+ sys.stdout.flush()
+
+def _on_timeout(proc, timeout_event):
+ timeout_event.set()
+ if proc.poll() == None:
+ try:
+ proc.terminate()
+ proc.wait()
+ # catch race condition if proc already dead
+ except OSError:
+ pass
+