]> granicus.if.org Git - python/commitdiff
Set a time threshold in test_asyncore.capture_server so that tests don't
authorKristján Valur Jónsson <kristjan@ccpgames.com>
Fri, 6 Apr 2012 14:37:45 +0000 (14:37 +0000)
committerKristján Valur Jónsson <kristjan@ccpgames.com>
Fri, 6 Apr 2012 14:37:45 +0000 (14:37 +0000)
deadlock if the main thread fails before sending all the data.

Lib/test/test_asyncore.py

index 1123c251ebd4ad29e9e031ed29db36a8936f458b..42a25255aeeb5b593a21ad12e37fa8194e09ecdd 100644 (file)
@@ -74,15 +74,16 @@ def capture_server(evt, buf, serv):
         pass
     else:
         n = 200
-        while n > 0:
-            r, w, e = select.select([conn], [], [])
+        start = time.time()
+        while n > 0 and time.time() - start < 3.0:
+            r, w, e = select.select([conn], [], [], 0.1)
             if r:
+                n -= 1
                 data = conn.recv(10)
                 # keep everything except for the newline terminator
                 buf.write(data.replace(b'\n', b''))
                 if b'\n' in data:
                     break
-            n -= 1
             time.sleep(0.01)
 
         conn.close()