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

Jeffrey Yasskin jyasskin at gmail.com
Wed Mar 5 04:40:18 CET 2008


On Tue, Mar 4, 2008 at 7:25 PM, Trent Nelson <tnelson at onresolve.com> wrote:
> > 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:
>

Yep, the alarm is only there to prevent what would be deadlocks from
running forever. Sorry for breaking !unix. Your patch looks fine to
me. Do you want to submit it or shall I?

>  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.
>
>
> _______________________________________________
>  Python-Dev mailing list
>  Python-Dev at python.org
>  http://mail.python.org/mailman/listinfo/python-dev
>  Unsubscribe: http://mail.python.org/mailman/options/python-dev/jyasskin%40gmail.com
>



-- 
Namasté,
Jeffrey Yasskin
http://jeffrey.yasskin.info/


More information about the Python-Dev mailing list