def _generateEvent( self, everyNSeconds, eventGenerator, plusOrMinusNSeconds, upToNEvents ):
if self._connectedEvent.wait( 0 ):
if upToNEvents is None or 0 != upToNEvents:
if upToNEvents is not None:
upToNEvents -= 1
try:
messages = next( eventGenerator )
except StopIteration:
self._log( "Scheduled event generator failed to generate, ignoring it in the future." )
return
else:
return
if type( messages ) not in ( tuple, list ):
messages = ( messages, )
self._sendFrame( HcpModuleId.HBS, messages, timeout = 30 )
if not self._stopEvent.wait( 0 ):
nextEvent = everyNSeconds
if 0 != plusOrMinusNSeconds:
nextEvent += random.randint( -plusOrMinusNSeconds, plusOrMinusNSeconds )
if 0 > nextEvent:
nextEvent = 0
self._threads.add( gevent.spawn_later( nextEvent, self._generateEvent, everyNSeconds, eventGenerator, plusOrMinusNSeconds, upToNEvents ) )
###########################################################################
# PUBLIC FUNCTIONALITY
###########################################################################
评论列表
文章目录