generator within a generator doesn't execute? 
Author Message
 generator within a generator doesn't execute?

from __future__ import generators
from time import time

threads=[]

def xsleep(n):
    t=time()
    while (t+n>time()):
        yield None

def sleep(n):
    for i in xsleep(n): pass

def cutscene():
    yield None #start on second pass

    print "\nEvil Death Knight: I will kill you now!"

    sleep(1.5)
    #t=time()
    #while (t+1.5>time()): yield None

    print "\nOur Hero: I shall fight you to the death.  Bring it on!"

    sleep(3)
    #t=time()
    #while (t+3>time()): yield None

    print "\nEnd of cutscene."

def ticker():
    yield None #wait till second time through
    print "."
    t=time()
    while 1:
        while (t+.5>time()): yield None
        t=time()
        #sleep(.5)
        print "."

def scheduler():
    global threads
    try:
        while 1:
            for thread in threads: thread.next()
    except StopIteration:
        pass

if __name__=="__main__":
    threads.append(ticker())
    threads.append(cutscene())
    scheduler()

I added xsleep() (a generator) and modified sleep() (now, not a generator).
cutscene() works as expected.  Why does sleep() block execution of ticker()?
Shouldn't xsleep() yield to the scheduler to allow ticker() to run?

Is there any way, save using Stackless python microthreads, to make the sleep
function 'just work' transparently?



Tue, 10 Jan 2006 21:03:37 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. generator function within a generator function doesn't execute?

2. Parser Generator/Scanner Generator for Scheme?

3. Wanted: parser-generator/lexical-analyser-generator outputting Scheme

4. Enhanced Generators - two-way generators

5. Generator syntax (was: Calling a generator multiple times)

6. 'dbdoc' database schema documentation generator

7. L'Ecuyer's random number generators

8. 'dbdoc' database schema documentation generator

9. Matlab Script doesn't execute code

10. php doesn't execute

11. I changed some tcl but it doesn't change when executing

12. dde execute doesn't clear data after error

 

 
Powered by phpBB® Forum Software