def compute_task(task=None):
import time
client = yield task.receive() # first message is client task
result = 0
while True:
n = yield task.receive()
if n is None: # end of requests
client.send(result)
break
# long-running computation (without 'yield') is simulated with
# 'time.sleep'; during this time client may send messages to this task
# (which will be received and put in this task's message queue) or this
# task can send messages to client
time.sleep(n)
result += n
# client (local) task runs computations
评论列表
文章目录