[pypy-svn] r61127 - in pypy/trunk/pypy/module/signal: . test

fijal at codespeak.net fijal at codespeak.net
Mon Jan 19 17:04:50 CET 2009


Author: fijal
Date: Mon Jan 19 17:04:49 2009
New Revision: 61127

Modified:
   pypy/trunk/pypy/module/signal/__init__.py
   pypy/trunk/pypy/module/signal/interp_signal.py
   pypy/trunk/pypy/module/signal/test/test_signal.py
Log:
implement alarm, pure fun


Modified: pypy/trunk/pypy/module/signal/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/signal/__init__.py	(original)
+++ pypy/trunk/pypy/module/signal/__init__.py	Mon Jan 19 17:04:49 2009
@@ -8,6 +8,7 @@
         'NSIG':                'space.wrap(interp_signal.NSIG)',
         'SIG_DFL':             'space.wrap(interp_signal.SIG_DFL)',
         'SIG_IGN':             'space.wrap(interp_signal.SIG_IGN)',
+        'alarm':               'interp_signal.alarm',
     }
 
     appleveldefs = {

Modified: pypy/trunk/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/trunk/pypy/module/signal/interp_signal.py	(original)
+++ pypy/trunk/pypy/module/signal/interp_signal.py	Mon Jan 19 17:04:49 2009
@@ -42,6 +42,7 @@
                                 lltype.Signed, _nowrapper=True)
 pypysig_set_occurred = external('pypysig_set_occurred', [lltype.Signed],
                                 lltype.Void, _nowrapper=True)
+c_alarm = external('alarm', [rffi.INT], rffi.INT)
 
 
 class SignalActionFlag(AbstractActionFlag):
@@ -150,6 +151,9 @@
     return space.wrap(SIG_DFL)
 getsignal.unwrap_spec = [ObjSpace, int]
 
+def alarm(space, timeout):
+    return c_alarm(timeout)
+alarm.unwrap_spec = [ObjSpace, int]
 
 def signal(space, signum, w_handler):
     """

Modified: pypy/trunk/pypy/module/signal/test/test_signal.py
==============================================================================
--- pypy/trunk/pypy/module/signal/test/test_signal.py	(original)
+++ pypy/trunk/pypy/module/signal/test/test_signal.py	Mon Jan 19 17:04:49 2009
@@ -115,3 +115,20 @@
             assert getsignal(SIGUSR1) is handler
         finally:
             signal(SIGUSR1, SIG_DFL)
+
+    def test_alarm(self):
+        from signal import alarm, signal, SIG_DFL, SIGALRM
+        import time
+        l = []
+        def handler(*a):
+            l.append(42)
+
+        try:
+            signal(SIGALRM, handler)
+            alarm(1)
+            time.sleep(2)
+            assert l == [42]
+            alarm(0)
+            assert l == [42]
+        finally:
+            signal(SIGALRM, SIG_DFL)



More information about the Pypy-commit mailing list