def client_proc(task=None):
# create channel
channel = pycos.Channel('sum_prod')
# create tasks to compute sum and product of numbers sent
sum_task = pycos.Task(seqsum)
prod_task = pycos.Task(seqprod)
# subscribe tasks to channel so they receive messages
yield channel.subscribe(sum_task)
yield channel.subscribe(prod_task)
# send 4 numbers to channel
for _ in range(4):
r = random.uniform(0.5, 3)
channel.send(r)
print('sent %f' % r)
# send None to indicate end of data
channel.send(None)
yield channel.unsubscribe(sum_task)
yield channel.unsubscribe(prod_task)
评论列表
文章目录