Last change
on this file since c3e41cda was 7bef8cf, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago |
start paper on llheap
|
-
Property mode
set to
100644
|
File size:
731 bytes
|
Line | |
---|
1 | def PingPong( name, N ):
|
---|
2 | partner = yield # get partner
|
---|
3 | yield # resume scheduler
|
---|
4 | for i in range( N ):
|
---|
5 | print( name )
|
---|
6 | yield partner # execute next
|
---|
7 | print( "end", name )
|
---|
8 |
|
---|
9 | def Scheduler():
|
---|
10 | n = yield # starting coroutine
|
---|
11 | try:
|
---|
12 | while True:
|
---|
13 | n = next( n ) # schedule coroutine
|
---|
14 | except StopIteration:
|
---|
15 | pass
|
---|
16 |
|
---|
17 | pi = PingPong( "ping", 5 )
|
---|
18 | po = PingPong( "pong", 5 )
|
---|
19 | next( pi ) # prime
|
---|
20 | pi.send( po ) # send partner
|
---|
21 | next( po ) # prime
|
---|
22 | po.send( pi ) # send partner
|
---|
23 |
|
---|
24 | s = Scheduler();
|
---|
25 | next( s ) # prime
|
---|
26 | try:
|
---|
27 | s.send( pi ) # start cycle
|
---|
28 | except StopIteration: # scheduler stopped
|
---|
29 | pass
|
---|
30 | print( "stop" )
|
---|
31 |
|
---|
32 | # Local Variables: #
|
---|
33 | # tab-width: 4 #
|
---|
34 | # compile-command: "python3.7 Pingpong.py" #
|
---|
35 | # End: #
|
---|
Note:
See
TracBrowser
for help on using the repository browser.