[pypy-svn] r35926 - in pypy/dist/pypy/lib: . app_test
stephan at codespeak.net
stephan at codespeak.net
Thu Dec 21 11:33:26 CET 2006
Author: stephan
Date: Thu Dec 21 11:33:22 2006
New Revision: 35926
Modified:
pypy/dist/pypy/lib/app_test/test_stackless.py
pypy/dist/pypy/lib/stackless_new.py
Log:
fixed some issues with channel handling. There is still some issue with
scheduling.
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 11:33:22 2006
@@ -450,7 +450,6 @@
assert r == 'test'
def test_simple_pipe(self):
- pypy_skip('should not fail, but does')
def pipe(X_in, X_out):
foo = X_in.receive()
X_out.send(foo)
@@ -462,21 +461,18 @@
assert Y.receive() == 42
def test_nested_pipe(self):
- pypy_skip('should not fail, but does')
- from stackless import run, tasklet, channel
-
def pipe(X, Y):
foo = X.receive()
Y.send(foo)
def nest(X, Y):
X2, Y2 = stackless.channel(), stackless.channel()
- stackless.tasklet(pipe)(X2, Y2)
+ t = stackless.tasklet(pipe)(X2, Y2)
X2.send(X.receive())
Y.send(Y2.receive())
X, Y = stackless.channel(), stackless.channel()
- stackless.tasklet(nest)(X, Y)
+ t1 = stackless.tasklet(nest)(X, Y)
X.send(42)
assert Y.receive() == 42
@@ -485,8 +481,11 @@
A tasklets/channels adaptation of the test_wait_two from the
logic object space
"""
- pypy_skip('should not fail, but does')
-
+ # there are still problems with scheduling. Apparently,
+ # 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()))
@@ -497,13 +496,15 @@
ret = Barrier.receive()
if ret[0] == X:
Ret_chan.send((1, ret[1]))
- return Ret_chan.send((2, ret[1]))
+ else:
+ Ret_chan.send((2, ret[1]))
X, Y, Ret_chan = stackless.channel(), stackless.channel(), stackless.channel()
stackless.tasklet(wait_two)(X, Y, Ret_chan)
Y.send(42)
X.send(42)
- assert Ret_chan.receive() == (2, 42)
+ value = Ret_chan.receive()
+ 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 11:33:22 2006
@@ -19,9 +19,24 @@
from collections import deque
import operator
-def deque_remove(dq, value):
- "deque.remove is only in python2.5"
- del dq[operator.indexOf(dq, value)]
+def _scheduler_remove(value):
+ try:
+ del squeue[operator.indexOf(squeue, value)]
+ except ValueError:pass
+
+def _scheduler_append(value, normal=True):
+ if normal:
+ squeue.append(value)
+ else:
+ squeue.appendleft(value)
+
+def _scheduler_contains(value):
+ try:
+ operator.indexOf(squeue, value)
+ return True
+ except ValueError:
+ return False
+
__all__ = 'run getcurrent getmain schedule tasklet channel coroutine \
TaskletExit greenlet'.split()
@@ -83,15 +98,13 @@
if self.balance > 0: # somebody is already sending
self.balance -= 1
sender = self.queue.popleft()
- #receiver.tempval = sender.tempval
+ sender.blocked = False
receiver.tempval = sender.tempval
- squeue.append(sender)
- #schedule()
+ _scheduler_append(sender)
else: # nobody is waiting
self.balance -= 1
- #squeue.pop()
- #deque_remove(receiver)
self.queue.append(receiver)
+ receiver.blocked = True
schedule_remove()
msg = receiver.tempval
return msg
@@ -108,12 +121,14 @@
sender.tempval = msg
if self.balance < 0: # somebody is already waiting
receiver = self.queue.popleft()
+ receiver.blocked = False
self.balance += 1
receiver.tempval = msg
- squeue.appendleft(receiver)
+ _scheduler_append(receiver, False)
schedule()
else: # nobody is waiting
- self.queue.append(squeue[-1])
+ self.queue.append(sender)
+ sender.blocked = True
self.balance += 1
schedule_remove()
@@ -135,6 +150,7 @@
global global_task_id
self.tempval = func
self.alive = False
+ self.blocked = False
self.task_id = global_task_id
global_task_id += 1
@@ -180,7 +196,7 @@
coroutine.bind(self,self.tempval,*argl,**argd)
self.tempval = None
self.alive = True
- squeue.append(self)
+ _scheduler_append(self)
return self
def __reduce__(self):
@@ -228,8 +244,6 @@
while squeue:
schedule()
-scall = 0
-
def schedule_remove(retval=None):
"""
schedule(retval=stackless.current) -- switch to the next runnable tasklet.
@@ -237,9 +251,7 @@
tasklet as default.
schedule_remove(retval=stackless.current) -- ditto, and remove self.
"""
- try:
- deque_remove(squeue, getcurrent())
- except:pass
+ _scheduler_remove(getcurrent())
schedule()
def schedule(retval=None):
@@ -262,7 +274,7 @@
if squeue:
pt = squeue.pop()
if pt.is_alive:
- squeue.append(pt)
+ _scheduler_append(pt)
else:
coroutine.kill(task)
else:
@@ -271,13 +283,13 @@
schedule()
elif task is curr:
if len(squeue) > 1:
+ if squeue[0] is squeue[-1]:
+ squeue.pop()
schedule()
elif not task.is_alive:
- try:
- deque_remove(squeue, task)
- except:pass
+ _scheduler_remove(task)
if not squeue:
- squeue.append(mtask)
+ _scheduler_append(mtask)
def _init():
global main_tasklet
@@ -312,6 +324,6 @@
assert main_tasklet.is_alive and not main_tasklet.is_zombie
tasklet._init(main_tasklet)
squeue = deque()
- squeue.append(main_tasklet)
+ _scheduler_append(main_tasklet)
_init()
More information about the Pypy-commit
mailing list