Lenard Lindstrom avatar Lenard Lindstrom committed b34a422

Fix unit test execution for Python 3.2 ( closes #83 )

The pygame.tests.testutils.async_sub module sets the stdout pipe to O_NONBLOCK.
Yet for linux a pipe set as O_NONBLOCK returns immediately from a select call,
even with nothing to read. This mucks up the Python 3.2 pipe read, which
expects something, and fails (a bug) when there is nothing.

Setting a socket to O_NONBLOCK is a good idea. A remote connection may
have a transmission error, which may trigger the select statement to
return, but subsequently invalidate the data so 0 bytes are returned on a read.
But a pipe, in this case, is inter-task; there should be no transmission errors.
Therefore the O_NONBLOCK should be unnecessary, and safely removed.

Comments (0)

Files changed (1)

test/test_utils/async_sub.py

             if conn is None:
                 return None
             
-            flags = fcntl.fcntl(conn, fcntl.F_GETFL)
-            if not conn.closed:
-                fcntl.fcntl(conn, fcntl.F_SETFL, flags| os.O_NONBLOCK)
+            if not select.select([conn], [], [], 0)[0]:
+                return ''
             
-            try:
-                if not select.select([conn], [], [], 0)[0]:
-                    return ''
-                
-                r = conn.read(maxsize)
-                if not r:
-                    return self._close(which)
-    
-                if self.universal_newlines:
-                    r = r.replace("\r\n", "\n").replace("\r", "\n")
-                return r
-            finally:
-                if not conn.closed:
-                    fcntl.fcntl(conn, fcntl.F_SETFL, flags)
+            r = conn.read(maxsize)
+            if not r:
+                return self._close(which)
+
+            if self.universal_newlines:
+                r = r.replace("\r\n", "\n").replace("\r", "\n")
+            return r
+
 
 ################################################################################
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.