Freeze and Resume execution

Miki Tebeka miki.tebeka at zoran.com
Mon May 24 02:47:05 EDT 2004


Hello Slawomir,

> def output_gen(bits):
>     size = 0
>     for bit in bits:
>         send_one_bit(bit) # HW call
>         size += 1
>         if size == OUT_BUFFER_SIZE:
>             yield "BufferFull" # use yield instead of raise here
>             size = 0
> 
> generator = None
> def output():
>     res = generator.next()
>     if res == "BufferFull": raise BufferFull
> 
> def sendall(bits):
>     global generator
>     generator = output_gen(bits)
>     while True:
>         try:
>             output()
>         except BufferFull:
>             print "Emptying buffer"
>         except StopIteration:
>             print "Done sending"
>             break
> 
> def test():
>     sendall("1234567890123456789012")
> 
> **********************************************************************
> 
> Catching BufferFull and calling output() doesn't need to be in
> sendall() function, it can basically be anywhere you want it to be.
> 
> Does this do what you want it to do?
It's not a complete solution but improves things *very much*.

Thanks!
--
-------------------------------------------------------------------------
Miki Tebeka <miki.tebeka at zoran.com>
http://www.cs.bgu.ac.il/~tebeka
The only difference between children and adults is the price of the toys.




More information about the Python-list mailing list