当前位置: 首页>>代码示例>>Python>>正文


Python reactor.getReaders函数代码示例

本文整理汇总了Python中twisted.internet.reactor.getReaders函数的典型用法代码示例。如果您正苦于以下问题:Python getReaders函数的具体用法?Python getReaders怎么用?Python getReaders使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getReaders函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_fds

        def _check_fds(_):
            # This appears to only be necessary for HTTPS tests.
            # For the normal HTTP tests then closeCachedConnections is
            # sufficient.
            fds = set(reactor.getReaders() + reactor.getReaders())
            if not [fd for fd in fds if isinstance(fd, Client)]:
                return

            return deferLater(reactor, 0, _check_fds, None)
开发者ID:ImmobilienScout24,项目名称:treq,代码行数:9,代码来源:test_treq_integration.py

示例2: tearDown

    def tearDown(self):
        try:
            yield self.pool.closeCachedConnections()
        except:
            pass

        while True:
            fds = set(reactor.getReaders() + reactor.getReaders())
            if not [fd for fd in fs if isinstance(fd, Client)]:
                break
开发者ID:PagerDuty,项目名称:txpypd,代码行数:10,代码来源:txentity.py

示例3: periodic_reporter

def periodic_reporter(settings):
    """Twisted Task function that runs every few seconds to emit general
    metrics regarding twisted and client counts"""
    settings.metrics.gauge("update.client.writers", len(reactor.getWriters()))
    settings.metrics.gauge("update.client.readers", len(reactor.getReaders()))
    settings.metrics.gauge("update.client.connections", len(settings.clients))
    settings.metrics.gauge("update.client.ws_connections", settings.factory.countConnections)
开发者ID:ncalexan,项目名称:autopush,代码行数:7,代码来源:websocket.py

示例4: print_runtime_info

def print_runtime_info(sig, frame):
    if sig in [signal.SIGUSR1, signal.SIGUSR2]:
        delayed = reactor.getDelayedCalls()
        readers = reactor.getReaders()
        writers = reactor.getWriters()
        clients = []
        http_conn_num = 0
        for reader in readers:
            if isinstance(reader, twisted.internet.tcp.Server):
                clients.append(reader.getPeer())
            if isinstance(reader, twisted.internet.tcp.Client):
                http_conn_num += 1
        log.msg(
            "[Clients: %(client_num)s] [HTTP Conns: %(http_conn_num)s] "
            "[Readers: %(reader_num)s] [Writers: %(writer_num)s] "
            "[DelayedCalls: %(delayed_num)s]"
            % {
                "client_num": len(clients),
                "http_conn_num": http_conn_num,
                "reader_num": len(readers),
                "writer_num": len(writers),
                "delayed_num": len(delayed),
            }
        )
        log.msg("[Connected Clients]: %s" % clients)
        if sig == signal.SIGUSR2:
            for d in delayed:
                log.msg("SIGUSR2[delayed]: %s" % d)

            for r in readers:
                log.msg("SIGUSR2[reader]: %s" % r)

            for w in writers:
                log.msg("SIGUSR2[writer]: %s" % w)
开发者ID:smerritt,项目名称:swftp,代码行数:34,代码来源:utils.py

示例5: customeTimeout

    def customeTimeout(self):
        print "main.CONNECTION_DONE: ", main.CONNECTION_DONE
        print "main.CONNECTION_LOST: ", main.CONNECTION_LOST
        print "self.sock: ", self.sock

        from twisted.internet import reactor
        print "reactor.getReaders(): ", reactor.getReaders()
        # check if self object is still in reactor:
        #   yes, means maybe not finished yet ...
        #   no, of course is done.
        if self in reactor.getReaders():
            # I will make it stop manually
            self.connectionLost( main.CONNECTION_DONE)
            print "invoke the self.connectionLost ... haha"
        else:
            print "already finished maybe ..."
开发者ID:JoySnow,项目名称:python_study_test,代码行数:16,代码来源:get-poetry-callLater.py

示例6: runtime_info

def runtime_info():
    delayed = reactor.getDelayedCalls()
    readers = reactor.getReaders()
    writers = reactor.getWriters()
    servers = []
    clients = []
    other = []
    for reader in readers:
        if isinstance(reader, tcp.Server):
            servers.append({
                'transport': reader,
                'host': reader.getHost(),
                'peer': reader.getPeer()
            })
        elif isinstance(reader, tcp.Client):
            clients.append({
                'transport': reader,
                'host': reader.getHost(),
                'peer': reader.getPeer()
            })
        else:
            other.append(reader)
    return {
        'num_clients': len(clients),
        'num_servers': len(servers),
        'num_other': len(other),
        'num_writers': len(writers),
        'num_delayed': len(delayed),
        'clients': clients,
        'servers': servers,
        'other': other,
        'writers': writers,
        'delayed': delayed,
    }
开发者ID:Libreno,项目名称:swftp,代码行数:34,代码来源:utils.py

示例7: checkReactor

    def checkReactor(self, phase, *_):
        delayed_calls = reactor.getDelayedCalls()
        if delayed_calls:
            self._logger.error("The reactor was dirty during %s:", phase)
            for dc in delayed_calls:
                self._logger.error(">     %s", dc)
                dc.cancel()

        from pony.orm.core import local
        if local.db_context_counter > 0:
            self._logger.error("Leftover pony db sessions found!")
        from pony.orm import db_session
        for _ in range(local.db_context_counter):
            db_session.__exit__()

        has_network_selectables = False
        for item in reactor.getReaders() + reactor.getWriters():
            if isinstance(item, HTTPChannel) or isinstance(item, Client):
                has_network_selectables = True
                break

        if has_network_selectables:
            # TODO(Martijn): we wait a while before we continue the check since network selectables
            # might take some time to cleanup. I'm not sure what's causing this.
            yield deferLater(reactor, 0.2, lambda: None)

        # This is the same check as in the _cleanReactor method of Twisted's Trial
        selectable_strings = []
        for sel in reactor.removeAll():
            if interfaces.IProcessTransport.providedBy(sel):
                self._logger.error("Sending kill signal to %s", repr(sel))
                sel.signalProcess('KILL')
            selectable_strings.append(repr(sel))

        self.assertFalse(selectable_strings,
                         "The reactor has leftover readers/writers during %s: %r" % (phase, selectable_strings))

        # Check whether we have closed all the sockets
        open_readers = reactor.getReaders()
        for reader in open_readers:
            self.assertNotIsInstance(reader, BasePort)

        # Check whether the threadpool is clean
        tp_items = len(reactor.getThreadPool().working)
        if tp_items > 0:  # Print all stacks to debug this issue
            self.watchdog.print_all_stacks()
        self.assertEqual(tp_items, 0, "Still items left in the threadpool")
开发者ID:synctext,项目名称:tribler,代码行数:47,代码来源:test_as_server.py

示例8: test_getReaders

    def test_getReaders(self):
        """
        Check that L{interfaces.IReactorFDSet.getReaders} reflects the actions
        made with L{interfaces.IReactorFDSet.addReader} and
        L{interfaces.IReactorFDSet.removeReader}.
        """
        s = socket.socket()
        self.addCleanup(s.close)

        c = Connection(s, protocol.Protocol())
        self.assertNotIn(c, reactor.getReaders())

        reactor.addReader(c)
        self.assertIn(c, reactor.getReaders())

        reactor.removeReader(c)
        self.assertNotIn(c, reactor.getReaders())
开发者ID:hortonworkstest,项目名称:hortonworks-sandbox,代码行数:17,代码来源:test_internet.py

示例9: tearDown

 def tearDown(self):
     from twisted.internet.tcp import Server
     # browsers has the bad habit on not closing the persistent
     # connections, so we need to hack them away to make trial happy
     f = failure.Failure(Exception("test end"))
     for reader in reactor.getReaders():
         if isinstance(reader, Server):
             reader.connectionLost(f)
开发者ID:Cray,项目名称:buildbot,代码行数:8,代码来源:test_www_oauth.py

示例10: status_thread

        def status_thread():
            last_str = None
            last_time = 0
            while True:
                yield deferral.sleep(3)
                try:
                    height = node.tracker.get_height(node.best_share_var.value)
                    this_str = 'P2Pool: %i shares in chain (%i verified/%i total) Peers: %i (%i incoming)' % (
                        height,
                        len(node.tracker.verified.items),
                        len(node.tracker.items),
                        len(node.p2p_node.peers),
                        sum(1 for peer in node.p2p_node.peers.itervalues() if peer.incoming),
                    ) + (' FDs: %i R/%i W' % (len(reactor.getReaders()), len(reactor.getWriters())) if p2pool.DEBUG else '')
                    
                    datums, dt = wb.local_rate_monitor.get_datums_in_last()
                    my_att_s = sum(datum['work']/dt for datum in datums)
                    my_shares_per_s = sum(datum['work']/dt/bitcoin_data.target_to_average_attempts(datum['share_target']) for datum in datums)
                    this_str += '\n Local: %sH/s in last %s Local dead on arrival: %s Expected time to share: %s' % (
                        math.format(int(my_att_s)),
                        math.format_dt(dt),
                        math.format_binomial_conf(sum(1 for datum in datums if datum['dead']), len(datums), 0.95),
                        math.format_dt(1/my_shares_per_s) if my_shares_per_s else '???',
                    )
                    
                    if height > 2:
                        (stale_orphan_shares, stale_doa_shares), shares, _ = wb.get_stale_counts()
                        stale_prop = p2pool_data.get_average_stale_prop(node.tracker, node.best_share_var.value, min(60*60//net.SHARE_PERIOD, height))
                        real_att_s = p2pool_data.get_pool_attempts_per_second(node.tracker, node.best_share_var.value, min(height - 1, 60*60//net.SHARE_PERIOD)) / (1 - stale_prop)
                        
                        this_str += '\n Shares: %i (%i orphan, %i dead) Stale rate: %s Efficiency: %s Current payout: %.4f %s' % (
                            shares, stale_orphan_shares, stale_doa_shares,
                            math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95),
                            math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95, lambda x: (1 - x)/(1 - stale_prop)),
                            node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(my_pubkey_hash), 0)*1e-8, net.PARENT.SYMBOL,
                        )
			print(node.bitcoind_work.value['bits'])
			print(real_att_s)
                        this_str += '\n Pool: %sH/s Stale rate: %.1f%% Expected time to block: %s' % (
                            math.format(int(real_att_s)),
                            100*stale_prop,
                            math.format_dt(2**256 / node.bitcoind_work.value['bits'].target / real_att_s),
                        )
                        
                        for warning in p2pool_data.get_warnings(node.tracker, node.best_share_var.value, net, bitcoind_getinfo_var.value, node.bitcoind_work.value):
                            print >>sys.stderr, '#'*40
                            print >>sys.stderr, '>>> Warning: ' + warning
                            print >>sys.stderr, '#'*40
                        
                        if gc.garbage:
                            print '%i pieces of uncollectable cyclic garbage! Types: %r' % (len(gc.garbage), map(type, gc.garbage))
                    
                    if this_str != last_str or time.time() > last_time + 15:
                        print this_str
                        last_str = this_str
                        last_time = time.time()
                except:
                    log.err()
开发者ID:ahmedbodi,项目名称:p2pool-dev-fee,代码行数:58,代码来源:main.py

示例11: assertReactorIsClean

    def assertReactorIsClean(self):
        """
        Check that the reactor has no delayed calls, readers or writers.
        """
        if reactor is None:
            return

        def raise_failure(location, reason):
            raise AssertionError(
                'Reactor is not clean. %s: %s' % (location, reason))

        if reactor._started:
            raise AssertionError('Reactor was not stopped.')

        # Look at threads queue.
        if len(reactor.threadCallQueue) > 0:
            raise_failure('threads', reactor.threadCallQueue)

        if self._threadPoolQueueSize() > 0:
            raise_failure('threadpoool queue', self._threadPoolQueueSize())

        if self._threadPoolWorking() > 0:
            raise_failure('threadpoool working', self._threadPoolWorking())

        if self._threadPoolThreads() > 0:
            raise_failure('threadpoool threads', self._threadPoolThreads())

        if len(reactor.getWriters()) > 0:
            raise_failure('writers', str(reactor.getWriters()))

        for reader in reactor.getReaders():
            excepted = False
            for reader_type in self.EXCEPTED_READERS:
                if isinstance(reader, reader_type):
                    excepted = True
                    break
            if not excepted:
                raise_failure('readers', str(reactor.getReaders()))

        for delayed_call in reactor.getDelayedCalls():
            if delayed_call.active():
                delayed_str = self._getDelayedCallName(delayed_call)
                if delayed_str in self.EXCEPTED_DELAYED_CALLS:
                    continue
                raise_failure('delayed calls', delayed_str)
开发者ID:chevah,项目名称:empirical,代码行数:45,代码来源:testcase.py

示例12: connectionLost

    def connectionLost(self,reason):
        self.sock.close()

        reactor.removeReader(self)

        for reader in reactor.getReaders():
            if isinstance(reader,PoetrySocket):
                return
        reactor.stop()
开发者ID:chen19901225,项目名称:SimplePyCode,代码行数:9,代码来源:get_poetry.py

示例13: test_runtime_info

 def test_runtime_info(self):
     """Make sure we add runtime info."""
     stats_worker = StatsWorker(self.service, 10)
     # get the reactor
     from twisted.internet import reactor
     stats_worker.runtime_info()
     # check the reactor data
     self.assertIn(('gauge', 'reactor.readers',
                    len(reactor.getReaders())), self.metrics.calls)
     self.assertIn(('gauge', 'reactor.writers',
                    len(reactor.getWriters())), self.metrics.calls)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:11,代码来源:test_stats.py

示例14: report_metrics

    def report_metrics(self):
        # Report collected metrics
        results = self.metrics
        self.reset_metrics()
        for name, value in results.items():
            self.metric.increment(name, value)

        # Generate/send Aux stats
        num_clients = len(
            [r for r in reactor.getReaders() if isinstance(r, tcp.Server)])
        self.metric.gauge('clients', num_clients)
开发者ID:benroeder,项目名称:swftp,代码行数:11,代码来源:statsd.py

示例15: connectionLost

    def connectionLost(self, reason):
        self.sock.close()

        # stop monitoring this socket
        from twisted.internet import reactor
        reactor.removeReader(self)

        # see if there are any poetry sockets left
        for reader in reactor.getReaders():
            if isinstance(reader, PoetrySocket):
                return

        reactor.stop() # no more poetry
开发者ID:bynoting,项目名称:python,代码行数:13,代码来源:get-poetry-broken.py


注:本文中的twisted.internet.reactor.getReaders函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。