osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

coroutines


Hello

Here a code for a simple demultiplexer coroutine

def demultiplexer(target1, target2):
    while True:
        data = yield
         target1.send(data)
         target2.send(data)

When data is sent to target1, what Cpython do 
immediately after ?

1- Go on execute demultiplexer, so send a data 
to target2 then pause demultiplexer when it reach
line data=yied, then execute coroutine target1, then 
execute coroutine target2

or

2- Go and execute target1 coroutine, then resume 
demultiplexer, so send a data to target2, go to target2, 
then resume demultiplexer and stops