Last active
June 10, 2021 02:49
-
-
Save dewaldabrie/021503a39be52d483a54e9f2e2d4155e to your computer and use it in GitHub Desktop.
Synchronous Generator Pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def func(targets, task_id, param=None): | |
print(f"{task_id}: Initialised with param: {param}") | |
while True: | |
inpt = (yield) | |
print(f"{task_id}: Received input: {inpt}") | |
time.sleep(1) # simulated IO delay | |
for target in targets: | |
print(f"{task_id}: T1 sending {inpt}") | |
target.send(inpt) | |
gen2 = func([], 'T2', "hello T2") | |
gen2.send(None) | |
gen1 = func([gen2], 'T1', "hello T1") | |
gen1.send(None) | |
start_time = time.time() | |
gen1.send(1) | |
gen1.send(2) | |
gen1.send(3) | |
print(f"Duration: {time.time() - start_time}") |
Line #16 should be:
gen1 = func([gen2], 'T1', "hello T1")
instead offunc[coro2]
for the code to work.
Thanks, I updated accordingly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line #16 should be:
gen1 = func([gen2], 'T1', "hello T1")
instead of
func[coro2]
for the code to work.