[Pytest-commit] commit/py: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jun 2 11:36:58 CEST 2014


2 new commits in py:

https://bitbucket.org/hpk42/py/commits/13e8b433f53c/
Changeset:   13e8b433f53c
Branch:      schlamar/dont-skip-exit-handlers-in-forkedfunc-t-1401701628841
User:        schlamar
Date:        2014-06-02 11:34:08
Summary:     Don't skip exit handlers in ForkedFunc.

This is achieved by using sys.exit instead of os._exit in the child
process. Additionally, it fixes a race condition where the temporary
directory could have been cleaned up in the child before the parent
has read its content.
Affected #:  1 file

diff -r f7c2b8011d273c2f69872b662c6b5765356827a5 -r 13e8b433f53cd689743557c3d3513683a89d3944 py/_process/forkedfunc.py
--- a/py/_process/forkedfunc.py
+++ b/py/_process/forkedfunc.py
@@ -3,8 +3,6 @@
     ForkedFunc provides a way to run a function in a forked process
     and get at its return value, stdout and stderr output as well
     as signals and exitstatusus.
-
-    XXX see if tempdir handling is sane
 """
 
 import py
@@ -12,8 +10,10 @@
 import sys
 import marshal
 
+
 class ForkedFunc(object):
     EXITSTATUS_EXCEPTION = 3
+
     def __init__(self, fun, args=None, kwargs=None, nice_level=0):
         if args is None:
             args = []
@@ -28,9 +28,10 @@
         self.STDERR = tempdir.ensure('stderr')
 
         pid = os.fork()
-        if pid: # in parent process
+        if pid:  # in parent process
             self.pid = pid
-        else: # in child process
+        else:  # in child process
+            self.pid = None
             self._child(nice_level)
 
     def _child(self, nice_level):
@@ -62,7 +63,7 @@
             retvalf.close()
         os.close(1)
         os.close(2)
-        os._exit(EXITSTATUS)
+        sys.exit(EXITSTATUS)
 
     def waitfinish(self, waiter=os.waitpid):
         pid, systemstatus = waiter(self.pid, 0)
@@ -71,8 +72,6 @@
                 exitstatus = os.WTERMSIG(systemstatus) + 128
             else:
                 exitstatus = os.WEXITSTATUS(systemstatus)
-            #raise ExecutionFailed(status, systemstatus, cmd,
-            #                      ''.join(out), ''.join(err))
         else:
             exitstatus = 0
         signal = systemstatus & 0x7f
@@ -95,7 +94,9 @@
             self.tempdir.remove()
 
     def __del__(self):
-        self._removetemp()
+        if self.pid is not None:  # only clean up in main process
+            self._removetemp()
+
 
 class Result(object):
     def __init__(self, exitstatus, signal, retval, stdout, stderr):


https://bitbucket.org/hpk42/py/commits/5d8aaac89ffc/
Changeset:   5d8aaac89ffc
User:        hpk42
Date:        2014-06-02 11:36:55
Summary:     Merged in schlamar/py/schlamar/dont-skip-exit-handlers-in-forkedfunc-t-1401701628841 (pull request #14)

Don't skip exit handlers in ForkedFunc.
Affected #:  1 file

diff -r f7c2b8011d273c2f69872b662c6b5765356827a5 -r 5d8aaac89ffc8d5077e612b8d067332c18753b2c py/_process/forkedfunc.py
--- a/py/_process/forkedfunc.py
+++ b/py/_process/forkedfunc.py
@@ -3,8 +3,6 @@
     ForkedFunc provides a way to run a function in a forked process
     and get at its return value, stdout and stderr output as well
     as signals and exitstatusus.
-
-    XXX see if tempdir handling is sane
 """
 
 import py
@@ -12,8 +10,10 @@
 import sys
 import marshal
 
+
 class ForkedFunc(object):
     EXITSTATUS_EXCEPTION = 3
+
     def __init__(self, fun, args=None, kwargs=None, nice_level=0):
         if args is None:
             args = []
@@ -28,9 +28,10 @@
         self.STDERR = tempdir.ensure('stderr')
 
         pid = os.fork()
-        if pid: # in parent process
+        if pid:  # in parent process
             self.pid = pid
-        else: # in child process
+        else:  # in child process
+            self.pid = None
             self._child(nice_level)
 
     def _child(self, nice_level):
@@ -62,7 +63,7 @@
             retvalf.close()
         os.close(1)
         os.close(2)
-        os._exit(EXITSTATUS)
+        sys.exit(EXITSTATUS)
 
     def waitfinish(self, waiter=os.waitpid):
         pid, systemstatus = waiter(self.pid, 0)
@@ -71,8 +72,6 @@
                 exitstatus = os.WTERMSIG(systemstatus) + 128
             else:
                 exitstatus = os.WEXITSTATUS(systemstatus)
-            #raise ExecutionFailed(status, systemstatus, cmd,
-            #                      ''.join(out), ''.join(err))
         else:
             exitstatus = 0
         signal = systemstatus & 0x7f
@@ -95,7 +94,9 @@
             self.tempdir.remove()
 
     def __del__(self):
-        self._removetemp()
+        if self.pid is not None:  # only clean up in main process
+            self._removetemp()
+
 
 class Result(object):
     def __init__(self, exitstatus, signal, retval, stdout, stderr):

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list