[Python-checkins] cpython (3.2): Speed up test_io by >2x by reducing the sleep time using setitimer instead of

gregory.p.smith python-checkins at python.org
Sun Jun 24 09:24:46 CEST 2012


http://hg.python.org/cpython/rev/e8f44ebacda7
changeset:   77671:e8f44ebacda7
branch:      3.2
parent:      77639:b6efb4c2995b
user:        Gregory P. Smith <greg at krypto.org>
date:        Sat Jun 23 23:46:37 2012 -0700
summary:
  Speed up test_io by >2x by reducing the sleep time using setitimer instead of
alarm for the signal tests.

files:
  Lib/test/test_io.py |  10 +++++-----
  1 files changed, 5 insertions(+), 5 deletions(-)


diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2868,7 +2868,7 @@
         try:
             wio = self.io.open(w, **fdopen_kwargs)
             t.start()
-            signal.alarm(1)
+            signal.setitimer(signal.ITIMER_REAL, 0.1)
             # Fill the pipe enough that the write will be blocking.
             # It will be interrupted by the timer armed above.  Since the
             # other thread has read one byte, the low-level write will
@@ -2912,7 +2912,7 @@
         r, w = os.pipe()
         wio = self.io.open(w, **fdopen_kwargs)
         try:
-            signal.alarm(1)
+            signal.setitimer(signal.ITIMER_REAL, 0.1)
             # Either the reentrant call to wio.write() fails with RuntimeError,
             # or the signal handler raises ZeroDivisionError.
             with self.assertRaises((ZeroDivisionError, RuntimeError)) as cm:
@@ -2947,7 +2947,7 @@
         try:
             rio = self.io.open(r, **fdopen_kwargs)
             os.write(w, b"foo")
-            signal.alarm(1)
+            signal.setitimer(signal.ITIMER_REAL, 0.1)
             # Expected behaviour:
             # - first raw read() returns partial b"foo"
             # - second raw read() returns EINTR
@@ -2991,13 +2991,13 @@
         t.daemon = True
         def alarm1(sig, frame):
             signal.signal(signal.SIGALRM, alarm2)
-            signal.alarm(1)
+            signal.setitimer(signal.ITIMER_REAL, 0.1)
         def alarm2(sig, frame):
             t.start()
         signal.signal(signal.SIGALRM, alarm1)
         try:
             wio = self.io.open(w, **fdopen_kwargs)
-            signal.alarm(1)
+            signal.setitimer(signal.ITIMER_REAL, 0.1)
             # Expected behaviour:
             # - first raw write() is partial (because of the limited pipe buffer
             #   and the first alarm)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list