Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r61431:8cf7d95bda59
Date: 2013-02-18 23:51 +0100
http://bitbucket.org/pypy/pypy/changeset/8cf7d95bda59/
Log: Fix module/thread tests when run with -A
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
@@ -25,19 +25,20 @@
print '*** timed out ***'
-def timeout_killer(pid, delay):
+def timeout_killer(cls, pid, delay):
def kill():
for x in range(delay * 10):
time.sleep(0.1)
try:
os.kill(pid, 0)
- except OSError, e:
+ except OSError as e:
if e.errno == errno.ESRCH: # no such process
return
raise
os.kill(pid, 9)
- print "process %s killed!" % (pid,)
- thread.start_new_thread(kill, ())
+ print("process %s killed!" % (pid,))
+ import threading
+ threading.Thread(target=kill).start()
class GenericTestThread:
@@ -45,21 +46,22 @@
def setup_class(cls):
if cls.runappdirect:
- def plain_waitfor(self, condition, delay=1):
+ cls.w_NORMAL_TIMEOUT = NORMAL_TIMEOUT
+ def plain_waitfor(cls, condition, delay=1):
+ import gc
+ import time
adaptivedelay = 0.04
- limit = time.time() + NORMAL_TIMEOUT * delay
+ limit = time.time() + cls.NORMAL_TIMEOUT * delay
while time.time() <= limit:
time.sleep(adaptivedelay)
gc.collect()
if condition():
return
adaptivedelay *= 1.05
- print '*** timed out ***'
+ print('*** timed out ***')
cls.w_waitfor = plain_waitfor
- def py_timeout_killer(self, *args, **kwargs):
- timeout_killer(*args, **kwargs)
- cls.w_timeout_killer = cls.space.wrap(py_timeout_killer)
+ cls.w_timeout_killer = timeout_killer
else:
@unwrap_spec(delay=int)
def py_waitfor(space, w_condition, delay=1):
@@ -73,7 +75,7 @@
(k, space.unwrap(v))
for k, v in kwargs_w.iteritems()
])
- timeout_killer(*args, **kwargs)
+ timeout_killer(cls, *args, **kwargs)
cls.w_timeout_killer =
cls.space.wrap(interp2app(py_timeout_killer))
cls.w_busywait = cls.space.appexec([], """():
diff --git a/pypy/module/thread/test/test_fork.py
b/pypy/module/thread/test/test_fork.py
--- a/pypy/module/thread/test/test_fork.py
+++ b/pypy/module/thread/test/test_fork.py
@@ -21,7 +21,7 @@
run = True
done = []
try:
- thread.start_new(busy_thread, ())
+ _thread.start_new(busy_thread, ())
print('sleep')
pid = os.fork()
diff --git a/pypy/module/thread/test/test_thread.py
b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -224,8 +224,8 @@
if waiting:
_thread.interrupt_main()
return
- print 'tock...', x # <-force the GIL to be released, as
- time.sleep(0.01) # time.sleep doesn't do non-translated
+ print('tock...', x) # <-force the GIL to be released, as
+ time.sleep(0.01) # time.sleep doesn't do non-translated
def busy_wait():
waiting.append(None)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit