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

Unified Diff: ppapi/native_client/tools/browser_tester/browsertester/browserprocess.py

Issue 10914053: Relocating files in the nacl repo that belong in chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 3 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
Index: ppapi/native_client/tools/browser_tester/browsertester/browserprocess.py
diff --git a/ppapi/native_client/tools/browser_tester/browsertester/browserprocess.py b/ppapi/native_client/tools/browser_tester/browsertester/browserprocess.py
new file mode 100755
index 0000000000000000000000000000000000000000..bca1734077427d36089149247f91f1ed0f92f790
--- /dev/null
+++ b/ppapi/native_client/tools/browser_tester/browsertester/browserprocess.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import signal
+import subprocess
+import time
+
+class BrowserProcessBase(object):
+
+ def __init__(self, handle):
+ self.handle = handle
+ print 'PID', self.handle.pid
+
+ def GetReturnCode(self):
+ return self.handle.returncode
+
+ def IsRunning(self):
+ return self.handle.poll() is None
+
+ def Wait(self, wait_steps, sleep_time):
+ self.term()
+ i = 0
+ # subprocess.wait() doesn't have a timeout, unfortunately.
+ while self.IsRunning() and i < wait_steps:
+ time.sleep(sleep_time)
+ i += 1
+
+ def Kill(self):
+ if self.IsRunning():
+ print 'KILLING the browser'
+ try:
+ self.kill()
+ # If it doesn't die, we hang. Oh well.
+ self.handle.wait()
+ except Exception:
+ # If it is already dead, then it's ok.
+ # This may happen if the browser dies after the first poll, but
+ # before the kill.
+ if self.IsRunning():
+ raise
+
+class BrowserProcess(BrowserProcessBase):
+
+ def term(self):
+ self.handle.terminate()
+
+ def kill(self):
+ self.handle.kill()
+
+
+class BrowserProcessPosix(BrowserProcessBase):
+ """ This variant of BrowserProcess uses process groups to manage browser
+ life time. """
+
+ def term(self):
+ os.killpg(self.handle.pid, signal.SIGTERM)
+
+ def kill(self):
+ os.killpg(self.handle.pid, signal.SIGKILL)
+
+
+def RunCommandWithSubprocess(cmd, env=None):
+ handle = subprocess.Popen(cmd, env=env)
+ return BrowserProcess(handle)
+
+
+def RunCommandInProcessGroup(cmd, env=None):
+ def SetPGrp():
+ os.setpgrp()
+ print 'I\'M THE SESSION LEADER!'
+ handle = subprocess.Popen(cmd, env=env, preexec_fn=SetPGrp)
+ return BrowserProcessPosix(handle)
+

Powered by Google App Engine
This is Rietveld 408576698