RosettaCodeData/Task/Synchronous-concurrency/Python/synchronous-concurrency-3.py

18 lines
302 B
Python
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
def reader():
for line in open('input.txt'):
yield line.rstrip()
count = yield None
print('Printed %d lines.' % count)
r = reader()
2013-10-27 22:24:23 +00:00
2013-04-11 01:07:29 -07:00
# printer
2013-10-27 22:24:23 +00:00
for count, line in enumerate(r):
if line is None:
2013-04-11 01:07:29 -07:00
break
print(line)
2013-10-27 22:24:23 +00:00
try:
r.send(count)
except StopIteration:
pass