python类deferLater()的实例源码

test_irc_messaging.py 文件源码 项目:joinmarket-clientserver 作者: JoinMarket-Org 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def on_welcome(mc):
    print('simulated on-welcome')
    mc.tx_irc_client.lineRate = 0.2
    if mc.nick == "irc_publisher":
        d = task.deferLater(reactor, 3.0, junk_pubmsgs, mc)
        d.addCallback(junk_longmsgs)
        d.addCallback(junk_announce)
        d.addCallback(junk_fill)
test_irc_messaging.py 文件源码 项目:joinmarket-clientserver 作者: JoinMarket-Org 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_waiter(self):
        print("test_main()")
        #reactor.callLater(1.0, junk_messages, self.mcc)
        return task.deferLater(reactor, 22, self._called_by_deffered)
test_daemon_protocol.py 文件源码 项目:joinmarket-clientserver 作者: JoinMarket-Org 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_waiter(self):
        return task.deferLater(reactor, 12, self._called_by_deffered)
test_daemon_protocol.py 文件源码 项目:joinmarket-clientserver 作者: JoinMarket-Org 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_waiter(self):
        return task.deferLater(reactor, 5, self._called_by_deffered)
vmware_exporter.py 文件源码 项目:vmware_exporter 作者: rverchere 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def render_GET(self, request):
        path = request.path.decode()
        request.setHeader("Content-Type", "text/plain; charset=UTF-8")
        if path == '/metrics':
            if not request.args.get('target', [None])[0]:
                request.setResponseCode(404)
                return 'No target defined\r\n'.encode()
            d = deferLater(reactor, 0, lambda: request)
            d.addCallback(self.generate_latest_target)
            d.addErrback(self.errback, request)
            return NOT_DONE_YET
        else:
            request.setResponseCode(404)
            return '404 Not Found'.encode()
test_util.py 文件源码 项目:py-ipv8 作者: qstokkink 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_blocking_call(self):
        """
        Check if the reactor thread is properly blocked by a function marked as such.
        """
        @blocking_call_on_reactor_thread
        @inlineCallbacks
        def waiter():
            # 'Release' our claim on the reactor thread.
            # blocking_call_on_reactor_thread should prevent anything else being scheduled though.
            yield deferLater(reactor, 0.01, lambda: None)
            waiter.variable += 1
            returnValue(waiter.variable)

        @blocking_call_on_reactor_thread
        def quicker():
            # Immediately use the reactor thread and return
            waiter.variable += 1
            return succeed(waiter.variable)

        waiter.variable = 1

        # 'Release' the reactor thread and increment waiter.variable
        # If release didn't allow other to be scheduled, waiter.variable is now 2
        # If quicker() came first, waiter.variable is now 3 (bad)
        value = yield waiter()
        # Claim reactor thread and increment waiter.variable
        # If waiter() came first, waiter.variable is now 3
        # If quicker() managed to sneak in before this, waiter.variable is now 2 (bad)
        value2 = yield quicker()

        self.assertEqual(value, 2)
        self.assertEqual(value2, 3)
test_util.py 文件源码 项目:py-ipv8 作者: qstokkink 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_blocking_call_in_thread(self):
        """
        Check if the reactor thread is properly blocked by a threaded function.
        """
        @blocking_call_on_reactor_thread
        @inlineCallbacks
        def waiter():
            # 'Release' our claim on the reactor thread.
            # blocking_call_on_reactor_thread should prevent anything else being scheduled though.
            yield deferLater(reactor, 0.01, lambda: None)
            waiter.variable += 1
            returnValue(waiter.variable)

        @blocking_call_on_reactor_thread
        def quicker():
            # Immediately use the reactor thread and return
            waiter.variable += 1
            return succeed(waiter.variable)

        waiter.variable = 1

        # 'Release' the reactor thread and increment waiter.variable
        # If release didn't allow other to be scheduled, waiter.variable is now 2
        # If quicker() came first, waiter.variable is now 3 (bad)
        value = yield deferToThread(waiter)
        # Claim reactor thread and increment waiter.variable
        # If waiter() came first, waiter.variable is now 3
        # If quicker() managed to sneak in before this, waiter.variable is now 2 (bad)
        value2 = yield deferToThread(quicker)

        self.assertEqual(value, 2)
        self.assertEqual(value2, 3)
test_taskmanager.py 文件源码 项目:py-ipv8 作者: qstokkink 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_delayed_deferred_requires_value(self):
        self.assertRaises(ValueError, self.tm.register_task, "test", deferLater(reactor, 0.0, lambda: None), delay=1)
base.py 文件源码 项目:py-ipv8 作者: qstokkink 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def sleep(self, time=.05):
        yield deferLater(reactor, time, lambda: None)
utils.py 文件源码 项目:checo 作者: kc1212 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def call_later(delay, f, *args, **kw):
    task.deferLater(reactor, delay, f, *args, **kw).addErrback(my_err_back)
consumers.py 文件源码 项目:Interactive_estimation 作者: adminq80 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def game_state_checker(game, state, round_data, users_plots, counter=0):
    if counter == SECONDS:
        # move to the next state
        if state == 'initial':
            start_interactive(game, round_data, users_plots)
        elif state == 'interactive':
            start_outcome(game, round_data, users_plots)
        else:
            start_initial(game)
        return

    if state == 'initial':
        r = InteractiveRound.objects.filter(game=game, round_order=round_data.get('current_round'), guess=None).count()
        if r == 0:
            start_interactive(game, round_data, users_plots)
            return
    elif state == 'interactive':
        r = InteractiveRound.objects.filter(game=game, round_order=round_data.get('current_round'),
                                            influenced_guess=None).count()
        if r == 0:
            start_outcome(game, round_data, users_plots)
            return
    elif state == 'outcome':
        r = InteractiveRound.objects.filter(game=game, round_order=round_data.get('current_round'),
                                            outcome=False).count()
        if r == 0:
            start_initial(game)
            return
    counter += 1
    task.deferLater(reactor, 1, game_state_checker, game, state, round_data, users_plots, counter).addErrback(
        twisted_error)
consumers.py 文件源码 项目:Interactive_estimation 作者: adminq80 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def start_interactive(game, round_data, users_plots):
    state = 'interactive'
    cache.set(game.id, {'state': state,
                        'round_data': round_data,
                        'users_plots': users_plots,
                        })
    for i in users_plots:
        user = i['user']
        round_data['plot'] = i['plot']
        interactive(user, game, round_data)
    task.deferLater(reactor, 1, game_state_checker, game, state, round_data, users_plots).addErrback(twisted_error)
    return
consumers.py 文件源码 项目:Interactive_estimation 作者: adminq80 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def start_outcome(game, round_data, users_plots):
    cache.set(game.id, {'state': 'outcome',
                        'round_data': round_data,
                        'users_plots': users_plots,
                        })
    for i in users_plots:
        user = i['user']
        round_data['plot'] = i['plot']
        outcome(user, game, round_data)
    task.deferLater(reactor, 1, game_state_checker, game, 'outcome', round_data, users_plots).addErrback(twisted_error)
tcp.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def loseConnection(self, connDone=failure.Failure(main.CONNECTION_DONE)):
        """
        Stop accepting connections on this port.

        This will shut down the socket and call self.connectionLost().  It
        returns a deferred which will fire successfully when the port is
        actually closed, or with a failure if an error occurs shutting down.
        """
        self.disconnecting = True
        self.stopReading()
        if self.connected:
            self.deferred = deferLater(
                self.reactor, 0, self.connectionLost, connDone)
            return self.deferred
test_task.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_errback(self):
        """
        The L{Deferred} returned by L{task.deferLater} is errbacked if the
        supplied function raises an exception.
        """
        def callable():
            raise TestException()

        clock = task.Clock()
        d = task.deferLater(clock, 1, callable)
        clock.advance(1)
        return self.assertFailure(d, TestException)
test_disttrial.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_runStopAfterTests(self):
        """
        L{DistTrialRunner} calls C{reactor.stop} and unlocks the test directory
        once the tests have run.
        """
        functions = []

        class FakeReactorWithSuccess(FakeReactor):

            def spawnProcess(self, worker, *args, **kwargs):
                worker.makeConnection(FakeTransport())
                self.spawnCount += 1
                worker._ampProtocol.run = self.succeedingRun

            def succeedingRun(self, case, result):
                return succeed(None)

            def addSystemEventTrigger(oself, phase, event, function):
                self.assertEqual('before', phase)
                self.assertEqual('shutdown', event)
                functions.append(function)

        workingDirectory = self.runner._workingDirectory

        fakeReactor = FakeReactorWithSuccess()
        self.runner.run(TestCase(), fakeReactor)

        def check():
            localLock = FilesystemLock(workingDirectory + ".lock")
            self.assertTrue(localLock.lock())
            self.assertEqual(1, fakeReactor.stopCount)
            # We don't wait for the process deferreds here, so nothing is
            # returned by the function before shutdown
            self.assertIdentical(None, functions[0]())

        return deferLater(reactor, 0, check)
test_log.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_inCallback(self):
            """
            Log an error in an asynchronous callback.
            """
            return task.deferLater(reactor, 0, lambda: log.err(makeFailure()))
concurrency.py 文件源码 项目:reflectrpc 作者: aheck 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def slow_operation():
    def calc_value(value):
        return 42

    return task.deferLater(reactor, 1, calc_value, None)
concurrency.py 文件源码 项目:reflectrpc 作者: aheck 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deferred_error():
    def calc_result(value):
        raise JsonRpcError("You wanted an error, here you have it!")

    return task.deferLater(reactor, 0.1, calc_result, None)
concurrency.py 文件源码 项目:reflectrpc 作者: aheck 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def deferred_internal_error():
    def calc_result(value):
        return 56 / 0

    return task.deferLater(reactor, 0.1, calc_result, None)


问题


面经


文章

微信
公众号

扫码关注公众号