Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py

Issue 2431223008: Make os.waitpid timeout on Windows. (Closed)
Patch Set: starts with lower case. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
diff --git a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
index bfe97d81c9b55bf1b895a97ad565957f9d21e63d..c0d245960be3d70e35bb1799105699d2200dcfbf 100644
--- a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
+++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
@@ -5,6 +5,7 @@
import argparse
import errno
+import multiprocessing
import os
import signal
import subprocess
@@ -49,6 +50,24 @@ def is_running_posix(pid):
return True
+def waitpid_for_win(pid):
+ """Return exception if raised in os.waitpid, or None.
+
+ Args:
+ pid(int): pid of process which this function checks
+ whether it is running or not.
+
+ Returns:
+ Exception: if something raised in os.waitpid.
+ None: otherwise.
+ """
+ try:
+ os.waitpid(pid, 0)
+ except Exception as e:
+ return e
+ return None
+
+
class NotDiedError(Exception):
def __str__(self):
return "NotDiedError"
@@ -79,13 +98,19 @@ def wait_termination(pid):
print('SIGINT has been sent to process %d. '
'Going to wait for the process finishes.' % pid)
if os.name == 'nt':
+ pool = multiprocessing.Pool(1)
+ res = pool.apply_async(waitpid_for_win)
try:
- os.waitpid(pid, 0)
- except OSError as e:
- if e.errno == errno.ECHILD:
- print('process %d died before waitpitd' % pid)
- return
- raise e
+ e = res.get(10)
+ except multiprocessing.TimeoutError:
+ print('process %d running more than 10 seconds' % pid)
+ raise NotDiedError()
+ if e is None:
+ return
+ if isinstance(e, OSError) and e.errno == errno.ECHILD:
+ print('process %d died before waitpitd' % pid)
+ return
+ raise e
else:
for _ in xrange(10):
time.sleep(1)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698