def deliver(self, message, timeout=None):
"""Must be used with 'yield' as 'yield task.deliver(message)'.
Can also be used on remotely running tasks.
Return value indicates status of delivering the message: If it is 1,
then message has been delivered, if it is 0, it couldn't be delivered
before timeout, and if it is < 0, then the (remote) task is not valid.
"""
if self._location:
request = _NetRequest('deliver', kwargs={'message': message, 'name': self._name,
'task': self._id},
dst=self._location, timeout=timeout)
request.reply = -1
reply = yield _Peer._sync_reply(request, alarm_value=0)
if reply is None:
reply = -1
# if reply < 0:
# logger.warning('remote task at %s may not be valid', self._location)
else:
reply = self._scheduler._resume(self, message, Pycos._AwaitMsg_)
if reply == 0:
reply = 1
raise StopIteration(reply)
评论列表
文章目录