[Pkg-privacy-commits] [pyptlib] 75/136: - add some extra comments and a warning for the temporary windows untidiness
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository pyptlib.
commit f872d91b4ccf2b36c7d2d683217df1428a3bc83e
Author: Ximin Luo <infinity0 at gmx.com>
Date: Wed Aug 7 18:24:35 2013 +0100
- add some extra comments and a warning for the temporary windows untidiness
---
pyptlib/test/test_util_subproc.py | 8 ++++++++
pyptlib/util/subproc.py | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/pyptlib/test/test_util_subproc.py b/pyptlib/test/test_util_subproc.py
index 421270f..9100127 100644
--- a/pyptlib/test/test_util_subproc.py
+++ b/pyptlib/test/test_util_subproc.py
@@ -34,14 +34,17 @@ class SubprocTest(unittest.TestCase):
return int(line.replace("child ", ""))
def test_Popen_IOpassthru(self):
+ """Test that output from the child passes through to the parent."""
output = subprocess.check_output(self.getMainArgs())
self.assertTrue(len(output) > 0)
def test_Popen_SINK(self):
+ """Test that output from the child is discarded when stdout = SINK."""
output = subprocess.check_output(self.getMainArgs())
self.assertTrue(len(output) == 0)
def test_trap_sigint_multiple(self):
+ """Test that adding multiple SIGINT handlers works as expected."""
proc = self.spawnMain()
proc.send_signal(signal.SIGINT)
self.assertEquals("run h1\n", proc.stdout.readline())
@@ -51,12 +54,14 @@ class SubprocTest(unittest.TestCase):
proc.terminate()
def test_trap_sigint_reset(self):
+ """Test that resetting SIGINT handlers works as expected."""
proc = self.spawnMain()
proc.send_signal(signal.SIGINT)
self.assertEquals("run h2\n", proc.stdout.readline())
proc.terminate()
def test_killall_kill(self):
+ """Test that killall() can kill -9 a hung process."""
proc = self.spawnMain()
pid = proc.pid
cid = self.readChildPid(proc)
@@ -68,6 +73,7 @@ class SubprocTest(unittest.TestCase):
proc.terminate()
def test_auto_killall_2_int(self):
+ """Test that auto_killall works for 2-INT signals."""
proc = self.spawnMain()
pid = proc.pid
cid = self.readChildPid(proc)
@@ -83,6 +89,7 @@ class SubprocTest(unittest.TestCase):
self.assertFalse(proc_is_alive(cid), "2 INT not handled")
def test_auto_killall_term(self):
+ """Test that auto_killall works for TERM signals."""
proc = self.spawnMain()
pid = proc.pid
cid = self.readChildPid(proc)
@@ -93,6 +100,7 @@ class SubprocTest(unittest.TestCase):
self.assertFalse(proc_is_alive(cid), "TERM not handled")
def test_auto_killall_exit(self):
+ """Test that auto_killall works on normal exit."""
proc = self.spawnMain()
pid = proc.pid
cid = self.readChildPid(proc)
diff --git a/pyptlib/util/subproc.py b/pyptlib/util/subproc.py
index 24522fa..25c6d6d 100644
--- a/pyptlib/util/subproc.py
+++ b/pyptlib/util/subproc.py
@@ -2,6 +2,8 @@
To have child processes actually be managed by this module, you should use
the Popen() here rather than subprocess.Popen() directly.
+
+Some parts do not yet work fully on windows (sending/trapping signals).
"""
import atexit
@@ -21,8 +23,13 @@ _CHILD_PROCS = []
SINK = object()
+# get default args from subprocess.Popen to use in subproc.Popen
a = inspect.getargspec(subprocess.Popen.__init__)
_Popen_defaults = zip(a.args[-len(a.defaults):],a.defaults); del a
+if mswindows:
+ # required for os.kill() to work
+ _Popen_defaults['creationflags'] |= subprocess.CREATE_NEW_PROCESS_GROUP
+
class Popen(subprocess.Popen):
"""Wrapper for subprocess.Popen that tracks every child process.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git
More information about the Pkg-privacy-commits
mailing list