[pypy-svn] r28694 - pypy/dist/pypy/module/stackless/test

stephan at codespeak.net stephan at codespeak.net
Mon Jun 12 10:01:47 CEST 2006


Author: stephan
Date: Mon Jun 12 10:01:45 2006
New Revision: 28694

Modified:
   pypy/dist/pypy/module/stackless/test/stack1.py
   pypy/dist/pypy/module/stackless/test/stack2.py
   pypy/dist/pypy/module/stackless/test/stackless_.py
Log:
examples stack1.py and stack2.py are working now.


Modified: pypy/dist/pypy/module/stackless/test/stack1.py
==============================================================================
--- pypy/dist/pypy/module/stackless/test/stack1.py	(original)
+++ pypy/dist/pypy/module/stackless/test/stack1.py	Mon Jun 12 10:01:45 2006
@@ -1,17 +1,19 @@
-from stackless_ import *
+import stackless
+if hasattr(stackless,'coroutine'):
+    import stackless_ as stackless
 
 def f():
-    print 'in f', getcurrent()
+    print 'in f', stackless.getcurrent()
 
 def g(t):
-    print 'in g %s' % t , getcurrent()
-    schedule()
+    print 'in g %s' % t , stackless.getcurrent()
+    stackless.schedule()
 
 def main():
-    cg = tasklet(g)('test')
-    cf = tasklet(f)()
-    run()
-    print 'in main', getcurrent()
+    cg = stackless.tasklet(g)('test')
+    cf = stackless.tasklet(f)()
+    stackless.run()
+    print 'in main', stackless.getcurrent()
 
 if __name__ == '__main__':
     main()

Modified: pypy/dist/pypy/module/stackless/test/stack2.py
==============================================================================
--- pypy/dist/pypy/module/stackless/test/stack2.py	(original)
+++ pypy/dist/pypy/module/stackless/test/stack2.py	Mon Jun 12 10:01:45 2006
@@ -26,13 +26,11 @@
     for i in range(10):
         print 'T1: sending',i
         outchan.send(i)
-        print 'T1: after sending'
     print 'T1: sending -1'
     outchan.send(-1)
 
 def g(inchan):
     while 1:
-        print 'T2: before receiving'
         val = inchan.receive()
         print 'T2: received',val
         if val == -1:

Modified: pypy/dist/pypy/module/stackless/test/stackless_.py
==============================================================================
--- pypy/dist/pypy/module/stackless/test/stackless_.py	(original)
+++ pypy/dist/pypy/module/stackless/test/stackless_.py	Mon Jun 12 10:01:45 2006
@@ -274,6 +274,8 @@
     tasklet that caused a timeout, if any.
     If an exception occours, it will be passed to the main tasklet.
     """
+    if DEBUG:
+        print 'stackless.run()'
     me = scheduler.current_remove()
     if me is not main_tasklet:
         raise RuntimeError("run() must be run from the main thread's \
@@ -281,6 +283,8 @@
     try:
         scheduler.schedule_task(me, scheduler._head)
     except Exception, exp:
+        if DEBUG:
+            print 'run: in Excpetion', exp
         b = curexc_to_bomb()
         main = main_tasklet
         SETVAL(main, b)
@@ -311,7 +315,7 @@
     """
     prev = scheduler._head
     next = prev.next
-    return scheduler.schedule_task(prev, next, 0)
+    return scheduler.schedule_task(prev, next)
 """
 /***************************************************************************
 
@@ -586,7 +590,7 @@
     def __init__(self):
         self.balance = 0
         self.closing = False
-        self.preference = 0
+        self.preference = -1
         self.next = self.prev = self
         self.schedule_all = False
         self.thread_id = -2
@@ -706,13 +710,20 @@
                     raise Exception('no interthreading: I can not be reached...')
                 else:
                     if self.schedule_all:
+                        if DEBUG:
+                            print '--- in if ---'
                         scheduler.current_insert(target)
                         target = source.next
                     elif self.preference == -d:
-                        scheduler._head = source.next
+                        if DEBUG:
+                            print '--- in elif ---'
+                        scheduler._set_head(source.next)
                         scheduler.current_insert(target)
-                        scheduler._head = source
+                        scheduler._set_head(source)
+                        #schedule._head = target
                     else:
+                        if DEBUG:
+                            print '--- else ---'
                         scheduler.current_insert(target)
                         target = source
             else:
@@ -850,7 +861,7 @@
 class Scheduler(object):
 
     def __init__(self):
-        self._head = getcurrent()
+        self._set_head(getcurrent())
 
     def _set_head(self, task):
         self._head = task
@@ -964,6 +975,7 @@
             SETVAL(prev, retval)
 
             return self.schedule_task(prev, prev)
+
         next = prev
         return self.schedule_task(prev, next)
 
@@ -988,6 +1000,8 @@
                     self.bomb_explode(prev)
                 return retval
             self._notify_schedule(prev, next, None)
+            #assert next is self._head
+            self._set_head(next)
         except Exception, exp:
             print '### Exception BEFORE switch', exp
             raise



More information about the Pypy-commit mailing list