[pypy-svn] r35938 - in pypy/dist/pypy/lib: . app_test
stephan at codespeak.net
stephan at codespeak.net
Thu Dec 21 17:05:25 CET 2006
Author: stephan
Date: Thu Dec 21 17:05:24 2006
New Revision: 35938
Modified:
pypy/dist/pypy/lib/app_test/test_stackless.py
pypy/dist/pypy/lib/stackless_new.py
Log:
added some debug code to test_stackless.py and added 'labels' to
tasklets/channels (non standard feature).
py.test is behaving very strangely together with stackless. In order to
see that, enable 'SHOW_STRANGE' in test_stackless.py. Two tests will
fail and will have some debug messages. It looks like the two test are
intertwined. Stange indeed.
Modified: pypy/dist/pypy/lib/app_test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/test_stackless.py (original)
+++ pypy/dist/pypy/lib/app_test/test_stackless.py Thu Dec 21 17:05:24 2006
@@ -18,6 +18,12 @@
except ImportError, e:
skip('cannot import stackless: %s' % (e,))
+SHOW_STRANGE = False
+
+def dprint(txt):
+ if SHOW_STRANGE:
+ print txt
+
def pypy_skip(txt):
"don't skip, if we are running with CStackless"
if not stackless_c:
@@ -380,7 +386,6 @@
import sys
b = stackless.bomb(*sys.exc_info())
assert b.type is ZeroDivisionError
- print str(b.value)
assert str(b.value).startswith('integer division')
assert b.traceback is not None
@@ -444,26 +449,42 @@
X_out.send(foo)
X, Y = stackless.channel(), stackless.channel()
- stackless.tasklet(pipe)(X, Y)
+ t = stackless.tasklet(pipe)(X, Y)
stackless.run()
X.send(42)
assert Y.receive() == 42
def test_nested_pipe(self):
+ dprint('tnp ==== 1')
def pipe(X, Y):
+ dprint('tnp_P ==== 1')
foo = X.receive()
+ dprint('tnp_P ==== 2')
Y.send(foo)
+ dprint('tnp_P ==== 3')
def nest(X, Y):
X2, Y2 = stackless.channel(), stackless.channel()
t = stackless.tasklet(pipe)(X2, Y2)
- X2.send(X.receive())
- Y.send(Y2.receive())
+ dprint('tnp_N ==== 1')
+ X_Val = X.receive()
+ dprint('tnp_N ==== 2')
+ X2.send(X_Val)
+ dprint('tnp_N ==== 3')
+ Y2_Val = Y2.receive()
+ dprint('tnp_N ==== 4')
+ Y.send(Y2_Val)
+ dprint('tnp_N ==== 5')
X, Y = stackless.channel(), stackless.channel()
t1 = stackless.tasklet(nest)(X, Y)
- X.send(42)
- assert Y.receive() == 42
+ X.send(13)
+ dprint('tnp ==== 2')
+ res = Y.receive()
+ dprint('tnp ==== 3')
+ assert res == 13
+ if SHOW_STRANGE:
+ raise Exception('force prints')
def test_wait_two(self):
"""
@@ -474,25 +495,43 @@
# some leftover tasklets in the queue are messing
# things up. This test runs fine, when being alone
# in a test file
- pypy_skip("still problems with scheduling")
- def sleep(X, Barrier):
- Barrier.send((X, X.receive()))
+ if not SHOW_STRANGE:
+ pypy_skip("still problems with scheduling")
+
+ def sleep(X, Y):
+ dprint('twt_S ==== 1')
+ value = X.receive()
+ dprint('twt_S ==== 2')
+ Y.send((X, value))
+ dprint('twt_S ==== 3')
def wait_two(X, Y, Ret_chan):
Barrier = stackless.channel()
stackless.tasklet(sleep)(X, Barrier)
stackless.tasklet(sleep)(Y, Barrier)
+ dprint('twt_W ==== 1')
ret = Barrier.receive()
+ dprint('twt_W ==== 2')
if ret[0] == X:
Ret_chan.send((1, ret[1]))
else:
Ret_chan.send((2, ret[1]))
+ dprint('twt_W ==== 3')
+
+ X = stackless.channel()
+ Y = stackless.channel()
+ Ret_chan = stackless.channel()
- X, Y, Ret_chan = stackless.channel(), stackless.channel(), stackless.channel()
stackless.tasklet(wait_two)(X, Y, Ret_chan)
+
+ dprint('twt ==== 1')
Y.send(42)
+
+ dprint('twt ==== 2')
X.send(42)
+ dprint('twt ==== 3')
value = Ret_chan.receive()
+ dprint('twt ==== 4')
assert value == (2, 42)
def test_noop(self):
Modified: pypy/dist/pypy/lib/stackless_new.py
==============================================================================
--- pypy/dist/pypy/lib/stackless_new.py (original)
+++ pypy/dist/pypy/lib/stackless_new.py Thu Dec 21 17:05:24 2006
@@ -53,6 +53,7 @@
_last_task = next
if _schedule_callback is not None:
_schedule_callback(current, next)
+ assert not next.blocked
next.switch()
return current
@@ -88,13 +89,14 @@
is resumed. If there is no waiting sender, the receiver is suspended.
"""
- def __init__(self):
+ def __init__(self, label=''):
self.balance = 0
self.closing = False
self.queue = deque()
+ self.label = label
def __str__(self):
- return 'channel(%s,%s)' % (self.balance, self.queue)
+ return 'channel[%s](%s,%s)' % (self.label, self.balance, self.queue)
def close(self):
"""
@@ -184,23 +186,24 @@
New tasklets can be created with methods from the stackless
module.
"""
- def __new__(cls, func=None):
+ def __new__(cls, func=None, label=''):
return super(tasklet,cls).__new__(cls)
- def __init__(self, func=None):
+ def __init__(self, func=None, label=''):
super(tasklet, self).__init__()
- self._init(func)
+ self._init(func, label)
- def _init(self, func=None):
+ def _init(self, func=None, label=''):
global _global_task_id
self.tempval = func
self.alive = False
self.blocked = False
- self.task_id = _global_task_id
+ self._task_id = _global_task_id
+ self.label = label
_global_task_id += 1
def __str__(self):
- return '<tasklet %s:%s>' % (self.task_id, self.is_alive)
+ return '<tasklet[%s, %s]>' % (self.label,self._task_id)
__repr__ = __str__
@@ -365,8 +368,7 @@
return getattr(self._coro,attr)
def __str__(self):
- return '<tasklet %s a:%s z:%s>' % \
- (self.task_id, self.is_alive, self.is_zombie)
+ return '<tasklet %s a:%s>' % (self._task_id, self.is_alive)
def __reduce__(self):
return getmain, ()
@@ -378,7 +380,7 @@
_main_coroutine = _main_tasklet
_main_tasklet = TaskletProxy(_main_tasklet)
assert _main_tasklet.is_alive and not _main_tasklet.is_zombie
- tasklet._init(_main_tasklet)
+ tasklet._init(_main_tasklet, label='main')
_squeue = deque()
_scheduler_append(_main_tasklet)
More information about the Pypy-commit
mailing list