VirtualSensor.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码
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
    ###########################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号