[Python-Dev] signal.alarm(3) in trunk test_socketserver.py

Trent Nelson tnelson at onresolve.com
Wed Mar 5 04:25:15 CET 2008


> r61099 added the following to trunk/Lib/test/test_socketserver.py:
>
>   if __name__ == "__main__":
>       test_main()
> +     signal.alarm(3)  # Shutdown shouldn't take more than 3 seconds.
>

Actually, signal.alarm() was introduced all over the place in that revision.  I understand the intent of this commit was to speed up the runtime of this test (something like 28s -> 0.3s was quoted in the commit log).  FWIW, runtime of the test with the following patch on Windows is 0.125s:

Index: test_socketserver.py
===================================================================
--- test_socketserver.py        (revision 61233)
+++ test_socketserver.py        (working copy)
@@ -28,6 +28,9 @@
 HAVE_UNIX_SOCKETS = hasattr(socket, "AF_UNIX")
 HAVE_FORKING = hasattr(os, "fork") and os.name != "os2"

+def signal_alarm(n):
+    if hasattr(signal, 'alarm'):
+        signal.alarm(n)

 def receive(sock, n, timeout=20):
     r, w, x = select.select([sock], [], [], timeout)
@@ -99,7 +102,7 @@
     """Test all socket servers."""

     def setUp(self):
-        signal.alarm(20)  # Kill deadlocks after 20 seconds.
+        signal_alarm(20)  # Kill deadlocks after 20 seconds.
         self.port_seed = 0
         self.test_files = []

@@ -112,7 +115,7 @@
             except os.error:
                 pass
         self.test_files[:] = []
-        signal.alarm(0)  # Didn't deadlock.
+        signal_alarm(0)  # Didn't deadlock.

     def pickaddr(self, proto):
         if proto == socket.AF_INET:
@@ -267,4 +270,4 @@

 if __name__ == "__main__":
     test_main()
-    signal.alarm(3)  # Shutdown shouldn't take more than 3 seconds.
+    signal_alarm(3)  # Shutdown shouldn't take more than 3 seconds.


More information about the Python-Dev mailing list