[pypy-commit] pypy kill-faking: fix thread tests

alex_gaynor noreply at buildbot.pypy.org
Sun Dec 2 22:49:34 CET 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: kill-faking
Changeset: r59235:aa12b7a661df
Date: 2012-12-02 13:49 -0800
http://bitbucket.org/pypy/pypy/changeset/aa12b7a661df/

Log:	fix thread tests

diff --git a/pypy/module/thread/test/support.py b/pypy/module/thread/test/support.py
--- a/pypy/module/thread/test/support.py
+++ b/pypy/module/thread/test/support.py
@@ -1,11 +1,15 @@
-import py
-import time, gc, thread, os
-from pypy.interpreter.gateway import ObjSpace, W_Root, interp2app_temp
+import gc
+import time
+import thread
+import os
+
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.module.thread import gil
 
 
 NORMAL_TIMEOUT = 300.0   # 5 minutes
 
+
 def waitfor(space, w_condition, delay=1):
     adaptivedelay = 0.04
     limit = time.time() + delay * NORMAL_TIMEOUT
@@ -19,6 +23,7 @@
         adaptivedelay *= 1.05
     print '*** timed out ***'
 
+
 def timeout_killer(pid, delay):
     def kill():
         for x in range(delay * 10):
@@ -28,6 +33,7 @@
         print "process %s killed!" % (pid,)
     thread.start_new_thread(kill, ())
 
+
 class GenericTestThread:
     spaceconfig = dict(usemodules=('thread', 'time', 'signal'))
 
@@ -43,15 +49,26 @@
                         return
                     adaptivedelay *= 1.05
                 print '*** timed out ***'
-                
+
             cls.w_waitfor = plain_waitfor
         else:
-            cls.w_waitfor = cls.space.wrap(
-                lambda self, condition, delay=1: waitfor(cls.space, condition, delay))
+            @unwrap_spec(delay=int)
+            def py_waitfor(space, w_condition, delay=1):
+                waitfor(space, w_condition, delay)
+
+            cls.w_waitfor = cls.space.wrap(interp2app(py_waitfor))
         cls.w_busywait = cls.space.appexec([], """():
             import time
             return time.sleep
         """)
-        
-        cls.w_timeout_killer = cls.space.wrap(
-            lambda self, *args, **kwargs: timeout_killer(*args, **kwargs))
+
+        def py_timeout_killer(space, __args__):
+            args_w, kwargs_w = __args__.unpack()
+            args = map(space.unwrap, args_w)
+            kwargs = dict([
+                (k, space.unwrap(v))
+                for k, v in kwargs_w.iteritems()
+            ])
+            timeout_killer(*args, **kwargs)
+
+        cls.w_timeout_killer = cls.space.wrap(interp2app(py_timeout_killer))


More information about the pypy-commit mailing list