[pypy-commit] pypy py3k: Merged in xentac/pypy/py3k-subprocess-new-session (pull request #143)

pjenvey noreply at buildbot.pypy.org
Wed Mar 20 23:19:02 CET 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r62584:27b08f6ff879
Date: 2013-03-20 15:18 -0700
http://bitbucket.org/pypy/pypy/changeset/27b08f6ff879/

Log:	Merged in xentac/pypy/py3k-subprocess-new-session (pull request
	#143)

	Set HAVE_SETSID if we have setsid so we can create new sessions in
	subprocesses

diff --git a/pypy/module/_posixsubprocess/interp_subprocess.py b/pypy/module/_posixsubprocess/interp_subprocess.py
--- a/pypy/module/_posixsubprocess/interp_subprocess.py
+++ b/pypy/module/_posixsubprocess/interp_subprocess.py
@@ -14,6 +14,7 @@
     _compilation_info_ = ExternalCompilationInfo(
         includes=['unistd.h', 'sys/syscall.h'])
     HAVE_SYS_SYSCALL_H = platform.Has("syscall")
+    HAVE_SETSID = platform.Has("setsid")
 
 config = platform.configure(CConfig)
 
@@ -24,10 +25,15 @@
                     'pypy_subprocess_init',
                     ])
 
+compile_extra = []
 if config['HAVE_SYS_SYSCALL_H']:
-    eci = eci.merge(
-        ExternalCompilationInfo(
-            compile_extra=["-DHAVE_SYS_SYSCALL_H"]))
+    compile_extra.append("-DHAVE_SYS_SYSCALL_H")
+if config['HAVE_SETSID']:
+    compile_extra.append("-DHAVE_SETSID")
+
+eci = eci.merge(
+    ExternalCompilationInfo(
+        compile_extra=compile_extra))
 
 c_child_exec = rffi.llexternal(
     'pypy_subprocess_child_exec',
diff --git a/pypy/module/_posixsubprocess/test/test_subprocess.py b/pypy/module/_posixsubprocess/test/test_subprocess.py
--- a/pypy/module/_posixsubprocess/test/test_subprocess.py
+++ b/pypy/module/_posixsubprocess/test/test_subprocess.py
@@ -38,3 +38,22 @@
 
         assert not (remaining_fds & open_fds), "Some fds were left open"
         assert 1 in remaining_fds, "Subprocess failed"
+
+    def test_start_new_session(self):
+        # For code coverage of calling setsid().  We don't care if we get an
+        # EPERM error from it depending on the test execution environment, that
+        # still indicates that it was called.
+        import subprocess
+        import os
+        try:
+            output = subprocess.check_output(
+                    ['/usr/bin/env', 'python', "-c",
+                     "import os; print(os.getpgid(os.getpid()))"],
+                    start_new_session=True)
+        except OSError as e:
+            if e.errno != errno.EPERM:
+                raise
+        else:
+            parent_pgid = os.getpgid(os.getpid())
+            child_pgid = int(output)
+            assert parent_pgid != child_pgid


More information about the pypy-commit mailing list