Exemplo n.º 1
0
 def _runSends(self, timeout=None, stop_on_available=False):
     numsends = 0
     endtime = ExpirationTimer(toTimeDeltaOrNone(timeout))
     for endt in unexpired(endtime):
         while self._pendingSends:
             numsends += 1
             if self.procLimit and numsends > self.procLimit:
                 raise RuntimeError('Too many sends')
             self._realizeWakeups()
             with self._private_lock:
                 try:
                     nextmsg = self._pendingSends.pop(0)
                 except IndexError:
                     pass
                 else:
                     self._runSingleSend(nextmsg)
             if stop_on_available and \
                any([not isInternalActorSystemMessage(M)
                     for M in getattr(stop_on_available.instance,
                                      'responses', [])]):
                 return
         if endt.remaining(forever=-1) == -1:
             return
         next_wakeup = self._next_wakeup()
         if next_wakeup is None or next_wakeup > endt:
             return
         time.sleep(
             max(0, timePeriodSeconds(next_wakeup.view().remaining())))
         self._realizeWakeups()
Exemplo n.º 2
0
 def ask(self, anActor, msg, timeout):
     txwatch = self._tx_to_actor(anActor, msg)  # KWQ: pass timeout on tx??
     askLimit = ExpirationTimer(toTimeDeltaOrNone(timeout))
     while not askLimit.expired():
         response = self._run_transport(askLimit.remaining())
         if txwatch.failed:
             if txwatch.failure in [SendStatus.DeadTarget,
                                    SendStatus.Failed,
                                    SendStatus.NotSent]:
                 # Silent failure; not all transports can indicate
                 # this, so for conformity the Dead Letter handler is
                 # the intended method of handling this issue.
                 return None
             raise ActorSystemFailure('Transmit of ask message to %s failed (%s)'%(
                 str(anActor),
                 str(txwatch.failure)))
         if not isinstance(response, ReceiveEnvelope):
             # Timed out or other failure, give up.
             break
         # Do not send miscellaneous ActorSystemMessages to the
         # caller that it might not recognize.  If one of those was
         # recieved, loop to get another response.
         if not isInternalActorSystemMessage(response.message):
             return response.message
     return None
Exemplo n.º 3
0
 def _runSends(self, timeout=None, stop_on_available=False):
     numsends = 0
     endtime = ((datetime.now() +
                 toTimeDeltaOrNone(timeout)) if timeout else None)
     while not endtime or datetime.now() < endtime:
         while self._pendingSends:
             numsends += 1
             if self.procLimit and numsends > self.procLimit:
                 raise RuntimeError('Too many sends')
             self._realizeWakeups()
             self._runSingleSend(self._pendingSends.pop(0))
             if stop_on_available and \
                any([not isInternalActorSystemMessage(M)
                     for M in getattr(stop_on_available.instance,
                                      'responses', [])]):
                 return
         if not endtime:
             return
         now = datetime.now()
         valid_wakeups = [(W - now) for W in self._wakeUps if W <= endtime]
         if not valid_wakeups:
             return
         import time
         time.sleep(max(0, timePeriodSeconds(min(valid_wakeups))))
         self._realizeWakeups()
Exemplo n.º 4
0
 def _runSends(self, timeout=None, stop_on_available=False):
     numsends = 0
     endtime = ExpirationTimer(toTimeDeltaOrNone(timeout))
     while not endtime.expired():
         while self._pendingSends:
             numsends += 1
             if self.procLimit and numsends > self.procLimit:
                 raise RuntimeError('Too many sends')
             self._realizeWakeups()
             with self._private_lock:
                 try:
                     nextmsg = self._pendingSends.pop(0)
                 except IndexError:
                     pass
                 else:
                     self._runSingleSend(nextmsg)
             if stop_on_available and \
                any([not isInternalActorSystemMessage(M)
                     for M in getattr(stop_on_available.instance,
                                      'responses', [])]):
                 return
         if endtime.remaining(forever=-1) == -1:
             return
         next_wakeup = self._next_wakeup()
         if next_wakeup is None or next_wakeup > endtime:
             return
         time.sleep(max(0, timePeriodSeconds(next_wakeup.remaining())))
         self._realizeWakeups()
Exemplo n.º 5
0
 def ask(self, anActor, msg, timeout):
     txwatch = self._tx_to_actor(anActor, msg)  # KWQ: pass timeout on tx??
     askLimit = ExpiryTime(toTimeDeltaOrNone(timeout))
     while not askLimit.expired():
         response = self._run_transport(askLimit.remaining())
         if txwatch.failed:
             if txwatch.failure in [SendStatus.DeadTarget,
                                    SendStatus.Failed,
                                    SendStatus.NotSent]:
                 # Silent failure; not all transports can indicate
                 # this, so for conformity the Dead Letter handler is
                 # the intended method of handling this issue.
                 return None
             raise ActorSystemFailure('Transmit of ask message to %s failed (%s)'%(
                 str(anActor),
                 str(txwatch.failure)))
         if response is None:
             # Timed out, give up.
             return None
         # Do not send miscellaneous ActorSystemMessages to the
         # caller that it might not recognize.  If one of those was
         # recieved, loop to get another response.
         if response and \
            hasattr(response, 'message') and \
            not isInternalActorSystemMessage(response.message):
             return response.message
     return None
Exemplo n.º 6
0
    def ask(self, anActor, msg, timeout):
        self._ASKFAILED = None
        self.transport.scheduleTransmit(
            None, TransmitIntent(anActor, msg, onError=self._askSendFailed))

        while True:
            response = self.transport.run(None, toTimeDeltaOrNone(timeout))
            if response is None: break
            if self._ASKFAILED is not None:
                if self._ASKFAILED in [
                        SendStatus.DeadTarget, SendStatus.Failed,
                        SendStatus.NotSent
                ]:
                    # Silent failure; not all transports can indicate
                    # this, so for conformity the Dead Letter handler is
                    # the intended method of handling this issue.
                    return None
                raise ActorSystemFailure(
                    'Transmit of ask message to %s failed (%s)' %
                    (str(anActor), str(self._ASKFAILED)))
            # Do not send miscellaneous ActorSystemMessages to the caller
            # that it might not recognize.
            if response and not isInternalActorSystemMessage(response.message):
                return response.message
        return None
Exemplo n.º 7
0
 def listen(self, timeout):
     while True:
         response = self.transport.run(None, toTimeDeltaOrNone(timeout))
         if response is None: break
         # Do not send miscellaneous ActorSystemMessages to the caller
         # that it might not recognize.
         if response and not isInternalActorSystemMessage(response.message):
             return response.message
     return None
Exemplo n.º 8
0
 def listen(self, timeout):
     while True:
         response = self._run_transport(toTimeDeltaOrNone(timeout))
         if not isinstance(response, ReceiveEnvelope):
             break
         # Do not send miscellaneous ActorSystemMessages to the caller
         # that it might not recognize.
         if not isInternalActorSystemMessage(response.message):
             return response.message
     return None
Exemplo n.º 9
0
 def listen(self, timeout):
     while True:
         response = self._run_transport(toTimeDeltaOrNone(timeout))
         if not isinstance(response, ReceiveEnvelope):
             break
         # Do not send miscellaneous ActorSystemMessages to the caller
         # that it might not recognize.
         if not isInternalActorSystemMessage(response.message):
             return response.message
     return None
Exemplo n.º 10
0
 def listen(self, timeout):
     while True:
         response = self._run_transport(toTimeDeltaOrNone(timeout))
         if response is None: break
         # Do not send miscellaneous ActorSystemMessages to the caller
         # that it might not recognize.
         if response and \
            hasattr(response, 'message') and \
            not isInternalActorSystemMessage(response.message):
             return response.message
     return None