python类loop()的实例源码

asyncorereactor.py 文件源码 项目:deb-python-cassandra-driver 作者: openstack 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def loop(self, timeout):
        asyncore.loop(timeout=timeout, use_poll=False, map=_dispatcher_map, count=1)
asyncorereactor.py 文件源码 项目:deb-python-cassandra-driver 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def loop(self, timeout):
        if not _dispatcher_map:
            time.sleep(0.005)
        count = timeout // self.max_write_latency
        asyncore.loop(timeout=self.max_write_latency, use_poll=True, map=_dispatcher_map, count=count)
asyncorereactor.py 文件源码 项目:deb-python-cassandra-driver 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _run_loop(self):
        log.debug("Starting asyncore event loop")
        with self._loop_lock:
            while not self._shutdown:
                try:
                    self._loop_dispatcher.loop(self.timer_resolution)
                    self._timers.service_timeouts()
                except Exception:
                    log.debug("Asyncore event loop stopped unexepectedly", exc_info=True)
                    break
            self._started = False

        log.debug("Asyncore event loop ended")
recipe-440690.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run( self ):
        while not self._stopevent.isSet():
            asyncore.loop( timeout = SmtpMailsink.TIME_TO_WAIT_BETWEEN_CHECKS_TO_STOP_SERVING, count = 1 )
test_create_organization.py 文件源码 项目:integration 作者: mendersoftware 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def start(self):
        self.server = smtpd_mock.SMTPServerMock(('0.0.0.0', 4444), None)
        asyncore.loop()
network_time_sync.py 文件源码 项目:esys-pbi 作者: fsxfreak 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self):
        asyncore.loop(use_poll=True,timeout=1)
network_time_sync.py 文件源码 项目:esys-pbi 作者: fsxfreak 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def stop(self):
        #we dont use server.close() as this raises a bad file decritoor exception in loop
        self.server.connected = False
        self.server.accepting = False
        self.server.del_channel()
        self.join()
        self.server.socket.close()
        logger.debug("Server Thread closed")
submitter.py 文件源码 项目:automated-arancino 作者: necst 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def main():
    wm = pyinotify.WatchManager()
    # watched events
    mask = pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE

    notifier = pyinotify.AsyncNotifier(wm, EventHandler())
    wdd = wm.add_watch(SAMPLES_DIR, mask, rec=True)

    asyncore.loop()
yowstack.py 文件源码 项目:whatsapp-rest-webservice 作者: svub 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def loop(self, *args, **kwargs):
        if "discrete" in kwargs:
            discreteVal = kwargs["discrete"]
            del kwargs["discrete"]
            while True:
                asyncore.loop(*args, **kwargs)
                time.sleep(discreteVal)
                try:
                    callback = self.__class__.__detachedQueue.get(False) #doesn't block
                    callback()
                except Queue.Empty:
                    pass
        else:
            asyncore.loop(*args, **kwargs)
asyndns.py 文件源码 项目:aquests 作者: hansroh 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def pop_all (self):
        # DNS query maybe not allowed delay between request and send
        # maybe they just drop response packet for delaying
        with self.lock:
            queue, self.queue = self.queue [:], []

        count = len (queue)
        while queue:
            name, args = queue.pop (0)
            self.handler.handle_request (name, **args)

        if (not count and not self.has_job ()):
            return

        map = {}
        with self.lock:
            for client in self.udps:
                map [client._fileno] = client
        fds = list (map.keys ())

        # maybe 2 is enough
        safeguard = count * 2
        while self.has_job () and safeguard:
            safeguard -= 1
            asyncore.loop (0.1, map, count = 1)
            if safeguard % 5 == 0:
                self.maintern (time.time ())        
        self.maintern (time.time ())

        for fd in fds:
            if fd not in map:
                # resync 
                try: del asyncore.socket_map [fd]
                except KeyError: pass
__init__.py 文件源码 项目:aquests 作者: hansroh 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _add (method, url, params = None, auth = None, headers = {}, callback = None, meta = None, proxy = None):   
    global _que, _initialized, _dns_query_req, _dns_reqs, _workers

    if not _initialized:        
        configure ()

    if not meta: 
        meta = {}

    meta ['req_id'] = _que.req_id
    meta ['req_method'] = method
    meta ['req_callback'] = callback
    _que.add ((method, url, params, auth, headers, meta, proxy))

    # DNS query for caching and massive
    if not lifetime._polling:
        host = urlparse (url) [1].split (":")[0]
        if _dns_reqs < _workers and host not in _dns_query_req:
            _dns_query_req [host] = None
            _dns_reqs += 1
            adns.query (host, "A", callback = lambda x: None)       
        asyndns.pop_all ()
        asyncore.loop (0.1, count = 2)

    #print ('~~~~~~~~~~~~~~~', asyndns.pool.connections)

#----------------------------------------------------
# Add Reuqest (protocols.*.request) Object
#----------------------------------------------------
asyncore_main.py 文件源码 项目:kivy-chat 作者: yingshaoxo 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def connect(self):
        self.host = self.root.ids.server.text
        self.nick = self.root.ids.nickname.text

        self.client = MySocketClient((self.host, PORT), self)
        threading.Thread(target=asyncore.loop).start()

        print('-- connecting to ' + self.host)

        self.root.current = 'chatroom'
flow.py 文件源码 项目:fixlib 作者: djc 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def loop(self, i, a, icond=None, acond=None, reset=False):

        if icond is not None:
            i.register('app', icond)
            i.register('admin', icond)
        if acond is not None:
            a.register('app', acond)
            a.register('admin', acond)

        i.logon(5, None, reset)
        asyncore.loop()
flow.py 文件源码 项目:fixlib 作者: djc 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def testlogon(self):
        i, a = self.setup()
        def cond(hook, msg):
            if hook == 'admin' and msg['MsgType'] == 'Logon':
                self.assertEquals(msg['SenderCompID'], 'B')
                self.assertEquals(msg['TargetCompID'], 'A')
                a.close()
                i.close()
        self.loop(i, a, cond, None)
flow.py 文件源码 项目:fixlib 作者: djc 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def testreset(self):
        i, a = self.setup()
        def cond(hook, msg):
            if hook == 'admin' and msg['MsgType'] == 'Logon':
                self.assertEquals(msg.get('ResetSeqNumFlag'), True)
                self.assertEquals(msg['MsgSeqNum'], 1)
                a.close()
                i.close()
        self.loop(i, a, cond, None, True)
__init__.py 文件源码 项目:continuum 作者: zyantific 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def enable_asyncore_loop(self):
        """Hooks our asyncore loop into Qt's event queue."""
        def beat():
            asyncore.loop(count=1, timeout=0)

        # Yep, this isn't especially real-time IO, but it's fine for what we do.
        timer = QTimer()
        timer.timeout.connect(beat)
        timer.setSingleShot(False)
        timer.setInterval(15)
        timer.start()

        self._timer = timer
__init__.py 文件源码 项目:continuum 作者: zyantific 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def disable_asyncore_loop(self):
        """Removes our asyncore loop from Qt's event queue."""
        self._timer = None
server.py 文件源码 项目:ice-mud-game 作者: PyBargain 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, host, port):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.address = (host, port)
        self.bind(self.address)
        self.listen(1)
        self.remote_clients = {}
        self.map = RaceMap(self)
        self.network_loop = threading.Thread(target = (lambda: asyncore.loop(timeout = 3)))
        self.packet_types = {'L': self.ServerPacketLogin,
                             'C': self.ServerPacketControl,
                             'E': self.ServerPacketLogout}
server.py 文件源码 项目:ice-mud-game 作者: PyBargain 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def tick(self, t):
        """
        Game loop
        """
        if len(self.player_data) > 0:
            self.game_started = True
            # tick player
            self.tick_player(t)
        elif self.game_started:
            self.running = False
        self.last_tick = t
mock_mail_server.py 文件源码 项目:dati-ckan-docker 作者: italia 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run(self):
        while not self._stop_event.isSet():
            asyncore.loop(timeout=0.01, count=1)


问题


面经


文章

微信
公众号

扫码关注公众号