Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r91649:dc929547a198
Date: 2017-06-26 19:27 +0200
http://bitbucket.org/pypy/pypy/changeset/dc929547a198/

Log:    Issue #2595: copies the test, and fix

diff --git a/lib_pypy/stackless.py b/lib_pypy/stackless.py
--- a/lib_pypy/stackless.py
+++ b/lib_pypy/stackless.py
@@ -268,12 +268,22 @@
         assert abs(d) == 1
         source = getcurrent()
         source.tempval = arg
-        if d > 0:
-            cando = self.balance < 0
-            dir = d
-        else:
-            cando = self.balance > 0
-            dir = 0
+        while True:
+            if d > 0:
+                cando = self.balance < 0
+                dir = d
+            else:
+                cando = self.balance > 0
+                dir = 0
+
+            if cando and not self.queue[0].alive:
+                # issue #2595: the tasklet was killed while waiting.
+                # drop that tasklet from consideration and try again.
+                self.balance += d
+                self.queue.popleft()
+            else:
+                # normal path
+                break
 
         if _channel_callback is not None:
             _channel_callback(self, source, dir, not cando)
diff --git a/pypy/module/test_lib_pypy/test_stackless.py 
b/pypy/module/test_lib_pypy/test_stackless.py
--- a/pypy/module/test_lib_pypy/test_stackless.py
+++ b/pypy/module/test_lib_pypy/test_stackless.py
@@ -600,4 +600,23 @@
 
         stackless.run()
 
-
+    def test_kill_tasklet_waiting_for_channel(self):
+        # issue #2595
+        c = stackless.channel()
+        def sender():
+            c.send(1)
+        def receiver():
+            v = c.receive()
+        def killer(tl):
+            tl.kill()
+        def main():
+            trk = stackless.tasklet(receiver)()
+            stackless.schedule()
+            killer(trk)
+            stackless.schedule()
+            stackless.tasklet(sender)()
+            stackless.schedule()
+            stackless.tasklet(receiver)()
+            stackless.schedule()
+        stackless.tasklet(main)()
+        stackless.run()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to