本文整理汇总了Python中thespian.system.utilis.ExpiryTime.expired方法的典型用法代码示例。如果您正苦于以下问题:Python ExpiryTime.expired方法的具体用法?Python ExpiryTime.expired怎么用?Python ExpiryTime.expired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thespian.system.utilis.ExpiryTime
的用法示例。
在下文中一共展示了ExpiryTime.expired方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateCapability
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def updateCapability(self, capabilityName, capabilityValue=None):
self._updCAPFAILED = False
attemptLimit = ExpiryTime(MAX_CAPABILITY_UPDATE_DELAY)
self.transport.scheduleTransmit(
None,
TransmitIntent(self.adminAddr,
CapabilityUpdate(capabilityName, capabilityValue),
onError = self._updateCapsFailed))
while not attemptLimit.expired():
if not self.transport.run(TransmitOnly, attemptLimit.remaining()):
break # all transmits completed
if self._updCAPFAILED or attemptLimit.expired():
raise ActorSystemFailure("Could not update Actor System Admin capabilities.")
示例2: unloadActorSource
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def unloadActorSource(self, sourceHash):
self._LOADFAILED = None
loadLimit = ExpiryTime(MAX_LOAD_SOURCE_DELAY)
self.transport.scheduleTransmit(None,
TransmitIntent(self.adminAddr,
ValidateSource(sourceHash, None),
onError = self._loadReqFailed))
while not loadLimit.expired():
if not self.transport.run(TransmitOnly, loadLimit.remaining()):
break # all transmits completed
if self._LOADFAILED or loadLimit.expired():
raise ActorSystemFailure('Unload source failed due to ' +
('failure response' if self._LOADFAILED else
'timeout (%s)'%str(loadLimit)))
示例3: loadActorSource
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def loadActorSource(self, fname):
self._LOADFAILED = None
loadLimit = ExpiryTime(MAX_LOAD_SOURCE_DELAY)
f = fname if hasattr(fname, 'read') else open(fname, 'rb')
try:
d = f.read()
import hashlib
hval = hashlib.md5(d).hexdigest()
self.transport.scheduleTransmit(None,
TransmitIntent(self.adminAddr,
ValidateSource(hval, d),
onError = self._loadReqFailed))
while not loadLimit.expired():
if not self.transport.run(TransmitOnly, loadLimit.remaining()):
break # all transmits completed
if self._LOADFAILED or loadLimit.expired():
raise ActorSystemFailure('Load source failed due to ' +
('failure response (%s)'%self._LOADFAILED
if self._LOADFAILED else
'timeout (%s)'%str(loadLimit)))
return hval
finally:
f.close()
示例4: __init__
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def __init__(self, system, logDefs = None):
self._numPrimaries = 0
# Expects self.transport has already been set by subclass __init__
self.adminAddr = self.transport.getAdminAddr(system.capabilities)
tryingTime = ExpiryTime(MAX_SYSTEM_SHUTDOWN_DELAY + timedelta(seconds=1))
while not tryingTime.expired():
if not self.transport.probeAdmin(self.adminAddr):
self._startAdmin(self.adminAddr,
self.transport.myAddress,
system.capabilities,
logDefs)
if self._verifyAdminRunning(): return
import time
time.sleep(0.5) # Previous version may have been exiting
if not self._verifyAdminRunning():
raise InvalidActorAddress(self.adminAddr,
'not a valid or useable ActorSystem Admin')
示例5: tell
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def tell(self, anActor, msg):
attemptLimit = ExpiryTime(MAX_TELL_PERIOD)
import socket
for attempt in range(5000):
try:
self.transport.scheduleTransmit(
None,
TransmitIntent(anActor, msg, onError=self._tellFailed))
while not attemptLimit.expired():
if not self.transport.run(TransmitOnly, attemptLimit.remaining()):
break # all transmits completed
return
except socket.error as ex:
import errno
if errno.EMFILE == ex.errno:
import time
time.sleep(0.1)
else:
raise
示例6: shutdown
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def shutdown(self):
thesplog('ActorSystem shutdown requested.', level=logging.INFO)
time_to_quit = ExpiryTime(MAX_SYSTEM_SHUTDOWN_DELAY)
self.transport.scheduleTransmit(
None,
TransmitIntent(self.adminAddr, SystemShutdown(),
onError=self._shutdownSendFailed))
while not time_to_quit.expired():
response = self.transport.run(None, time_to_quit.remaining())
if getattr(self, '_TASF', False):
thesplog('Could not send shutdown request to Admin'
'; aborting but not necessarily stopped',
level=logging.WARNING)
return
if response:
if isinstance(response.message, SystemShutdownCompleted):
break
else:
thesplog('Expected shutdown completed message, got: %s', response.message,
level=logging.WARNING)
else:
thesplog('No response to Admin shutdown request; Actor system not completely shutdown',
level=logging.ERROR)
thesplog('ActorSystem shutdown complete.')
示例7: drainTransmits
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def drainTransmits(self):
drainLimit = ExpiryTime(MAX_SHUTDOWN_DRAIN_PERIOD)
while not drainLimit.expired():
if not self.transport.run(TransmitOnly, drainLimit.remaining()):
break # no transmits left
示例8: HysteresisDelaySender
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
class HysteresisDelaySender(object):
"""Implements hysteresis delay for sending messages. This is intended
to be used for messages exchanged between convention members to
ensure that a mis-behaved member doesn't have the ability to
inflict damage on the entire convention. The first time a
message is sent via this sender it is passed on through, but
that starts a blackout period that starts with the
CONVENTION_HYSTERESIS_MIN_PERIOD. Each additional send attempt
during that blackout period will cause the blackout period to
be extended by the CONVENTION_HYSTERESIS_RATE, up to the
CONVENTION_HYSTERESIS_MAX_PERIOD. Once the blackout period
ends, the queued sends will be sent, but only the last
attempted message of each type for the specified remote target.
At that point, the hysteresis delay will be reduced by the
CONVENTION_HYSTERESIS_RATE; further send attempts will affect
the hysteresis blackout period as described as above but lack
of sending attempts will continue to reduce the hysteresis back
to a zero-delay setting.
Note: delays are updated in a target-independent manner; the
target is only considered when eliminating duplicates.
Note: maxDelay on TransmitIntents is ignored by hysteresis
delays. It is assumed that a transmit intent's maxDelay
is greater than the maximum hysteresis period and/or that
the hysteresis delay is more important than the transmit
intent timeout.
"""
def __init__(self, actual_sender,
hysteresis_min_period = HYSTERESIS_MIN_PERIOD,
hysteresis_max_period = HYSTERESIS_MAX_PERIOD,
hysteresis_rate = HYSTERESIS_RATE):
self._sender = actual_sender
self._hysteresis_until = ExpiryTime(timedelta(seconds=0))
self._hysteresis_queue = []
self._duplicate_queue = []
self._current_hysteresis = None # timedelta
self._hysteresis_min_period = hysteresis_min_period
self._hysteresis_max_period = hysteresis_max_period
self._hysteresis_rate = hysteresis_rate
@property
def delay(self): return self._hysteresis_until
def checkSends(self):
if self.delay.expired():
hsends = self._hysteresis_queue
self._hysteresis_queue = []
self._current_hysteresis = (
None
if (self._current_hysteresis is None or
self._current_hysteresis < self._hysteresis_min_period) else
self._current_hysteresis / self._hysteresis_rate)
self._hysteresis_until = ExpiryTime(self._current_hysteresis
if self._current_hysteresis else
timedelta(seconds=0))
for intent in hsends:
self._sender(intent)
def sendWithHysteresis(self, intent):
if self._hysteresis_until.expired():
self._current_hysteresis = self._hysteresis_min_period
self._sender(intent)
else:
dups = self._keepIf(lambda M: (M.targetAddr != intent.targetAddr or
type(M.message) != type(intent.message)))
# The dups are duplicate sends to the new intent's target; complete them when
# the actual message is finally sent with the same result
if dups:
intent.addCallback(self._dupSentGood(dups), self._dupSentFail(dups))
self._hysteresis_queue.append(intent)
self._current_hysteresis = min(
(self._hysteresis_min_period
if (self._current_hysteresis is None or
self._current_hysteresis < self._hysteresis_min_period) else
self._current_hysteresis * self._hysteresis_rate),
self._hysteresis_max_period)
self._hysteresis_until = ExpiryTime(
timedelta(seconds=0)
if not self._current_hysteresis else
(self._current_hysteresis -
(timedelta(seconds=0)
if not self._hysteresis_until else
self._hysteresis_until.remaining())))
def cancelSends(self, remoteAddr):
cancels = self._keepIf(lambda M: M.targetAddr != remoteAddr)
for each in cancels:
each.result = SendStatus.Failed
each.completionCallback()
def _keepIf(self, keepFunc):
requeues, removes = partition(keepFunc, self._hysteresis_queue)
self._hysteresis_queue = requeues
return removes
@staticmethod
def _dupSentGood(dups):
def _finishDups(result, finishedIntent):
for each in dups:
each.result = result
each.completionCallback()
return _finishDups
@staticmethod
def _dupSentFail(dups):
def _finishDups(result, finishedIntent):
#.........这里部分代码省略.........
示例9: ConventioneerAdmin
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
#.........这里部分代码省略.........
# a Convention Deregistration) then it should not be
# necessary to shutdown remote Actors (or notify of their
# shutdown) because the remote ActorSystem should already
# have caused this to occur. However, it won't hurt, and
# it's necessary if the remote ActorSystem did not exit
# gracefully.
for lpa, raa in cmr.hasRemoteActors:
# ignore errors:
self._send_intent(TransmitIntent(lpa, ChildActorExited(raa)))
# n.b. at present, this means that the parent might
# get duplicate notifications of ChildActorExited; it
# is expected that Actors can handle this.
# Remove remote system from conventionMembers
del self._conventionMembers[registrant.actorAddressString]
if registrant == self._conventionAddress:
# Convention Leader has exited. Do NOT set
# conventionAddress to None. It might speed up shutdown
# of this ActorSystem because it won't try to de-register
# from the convention leader, but if the convention leader
# reappears there will be nothing to get this ActorSystem
# re-registered with the convention.
self._conventionLeaderIsGone = True
self._hysteresisSender.cancelSends(registrant)
def _checkConvention(self):
if self.isConventionLeader():
missing = []
for each in self._conventionMembers:
if self._conventionMembers[each].registryValid.expired():
missing.append(each)
for each in missing:
thesplog('%s missed %d checkins (%s); assuming it has died',
str(self._conventionMembers[each]),
CONVENTION_REGISTRATION_MISS_MAX,
str(self._conventionMembers[each].registryValid),
level=logging.WARNING, primary=True)
self._remoteSystemCleanup(self._conventionMembers[each].remoteAddress)
self._conventionRegistration = ExpiryTime(CONVENTION_REREGISTRATION_PERIOD)
else:
# Re-register with the Convention if it's time
if self._conventionAddress and self._conventionRegistration.expired():
self.setupConvention()
def run(self):
try:
while not self.isShuttingDown():
delay = min(self._conventionRegistration or \
ExpiryTime(CONVENTION_RESTART_PERIOD
if self._conventionLost and not self.isConventionLeader() else
CONVENTION_REREGISTRATION_PERIOD),
ExpiryTime(None) if self._hysteresisSender.delay.expired() else
self._hysteresisSender.delay
)
self.transport.run(self.handleIncoming, delay.remaining())
self._checkConvention()
self._hysteresisSender.checkSends()
except Exception as ex:
import traceback
thesplog('ActorAdmin uncaught exception: %s', traceback.format_exc(),
level=logging.ERROR, exc_info=True)
示例10: testNonZeroExpired
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def testNonZeroExpired(self):
et = ExpiryTime(timedelta(milliseconds=10))
self.assertFalse(et.expired())
sleep(et.remainingSeconds())
self.assertTrue(et.expired())
示例11: testZeroExpired
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def testZeroExpired(self):
et = ExpiryTime(timedelta(seconds=0))
self.assertTrue(et.expired())
示例12: testNoneExpired
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
def testNoneExpired(self):
et = ExpiryTime(None)
self.assertFalse(et.expired())
示例13: wakeupTransportBase
# 需要导入模块: from thespian.system.utilis import ExpiryTime [as 别名]
# 或者: from thespian.system.utilis.ExpiryTime import expired [as 别名]
class wakeupTransportBase(object):
"""The wakeupTransportBase is designed to be used as a mixin-base for
a Transport class and provides handling for the wakeupAfter()
functionality.
This base mixin provides the primary .run() entrypoint for the
transport and a .run_time ExpiryTime member that provides the
remaining time-to-run period.
The system can handle .wakeupAfter() requests by calling this
class's .addWakeup() method with the datetime.timedelta for the
wakeup to be scheduled.
The Transport should provide the following:
._runWithExpiry(incomingHandler)
Called by this class's .run() entrypoint to do the
actual transport-specific run routine. Should perform
that activity while the self.run_time ExpiryTime is not
expired (self.run_time will be updated when new
wakeupAfter() events are scheduled).
"""
def __init__(self, *args, **kw):
super(wakeupTransportBase, self).__init__(*args, **kw)
# _pendingWakeups: key = datetime for wakeup, value = list of
# pending wakeupAfter msgs to restart at that time
self._pendingWakeups = {}
self._activeWakeups = [] # expired wakeups to be delivered
def _updateStatusResponse(self, resp):
"Called to update a Thespian_SystemStatus or Thespian_ActorStatus with common information"
resp.addWakeups(self._pendingWakeups)
for each in self._activeWakeups:
resp.addPendingMessage(self.myAddress, self.myAddress, str(each.message))
def run(self, incomingHandler, maximumDuration=None):
"""Core scheduling method; called by the current Actor process when
idle to await new messages (or to do background
processing).
"""
self._max_runtime = ExpiryTime(maximumDuration)
while not self._max_runtime.expired():
now = datetime.now()
self.run_time = min([ExpiryTime(P - now) for P in self._pendingWakeups] +
[self._max_runtime])
rval = self._runWithExpiry(incomingHandler)
if rval is not None:
return rval
if not self._realizeWakeups():
# No wakeups were processed, and the inner run
# returned, so assume there's nothing to do and exit
return rval
while self._activeWakeups:
w = self._activeWakeups.pop()
if incomingHandler in (None, TransmitOnly):
return w
if not incomingHandler(w):
return None
return None
def addWakeup(self, timePeriod):
now = datetime.now()
wakeupTime = now + timePeriod
self._pendingWakeups.setdefault(wakeupTime, []) \
.append(ReceiveEnvelope(self.myAddress, WakeupMessage(timePeriod)))
self.run_time = min([ExpiryTime(P - now) for P in self._pendingWakeups] +
[self._max_runtime])
def _realizeWakeups(self):
"Find any expired wakeups and queue them to the send processing queue"
now = datetime.now()
removals = []
for wakeupTime in self._pendingWakeups:
if wakeupTime > now:
continue
self._activeWakeups.extend(self._pendingWakeups[wakeupTime])
removals.append(wakeupTime)
for each in removals:
del self._pendingWakeups[each]
return bool(removals)