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


Python ResizableDispatchQueue.stop方法代码示例

本文整理汇总了Python中txrdq.rdq.ResizableDispatchQueue.stop方法的典型用法代码示例。如果您正苦于以下问题:Python ResizableDispatchQueue.stop方法的具体用法?Python ResizableDispatchQueue.stop怎么用?Python ResizableDispatchQueue.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txrdq.rdq.ResizableDispatchQueue的用法示例。


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

示例1: testZeroOnExplicitCreation

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testZeroOnExplicitCreation(self):
     """
     A new queue whose width is 10 should have no pending stops.
     """
     dq = ResizableDispatchQueue(None, 10)
     self.assertEqual(0, dq.pendingStops)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:9,代码来源:test_rdq.py

示例2: testZeroOnDefaultCreation

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testZeroOnDefaultCreation(self):
     """
     A new queue whose width is unspecified should have no pending
     stops.
     """
     dq = ResizableDispatchQueue(None)
     self.assertEqual(0, dq.pendingStops)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:10,代码来源:test_rdq.py

示例3: testPutRaisesWhenStopped

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testPutRaisesWhenStopped(self):
     """
     Putting something onto a stopped queue should raise
     C{QueueStopped}.
     """
     dq = ResizableDispatchQueue(None)
     yield dq.stop()
     self.assertRaises(QueueStopped, dq.put, None)
开发者ID:jcollie,项目名称:txrdq,代码行数:10,代码来源:test_rdq.py

示例4: testIncrementToVeryHighValue

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testIncrementToVeryHighValue(self):
     """
     Create a queue of width 10 and then set its width to 1000.
     The number of pending stops will be 0.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 1000
     self.assertEqual(dq.pendingStops, 0)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:11,代码来源:test_rdq.py

示例5: testSetImmediatelyToZero

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testSetImmediatelyToZero(self):
     """
     Create a queue of width 10 and then set its width to 0.
     The number of pending stops will be 10.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 0
     self.assertEqual(dq.pendingStops, 10)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:11,代码来源:test_rdq.py

示例6: testNarrow

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testNarrow(self):
     """
     Create a queue of width 5 and narrow it to width 3. There should
     then be 2 pending stops.
     """
     dq = ResizableDispatchQueue(None, 5)
     dq.width = 3
     self.assertEqual(2, dq.pendingStops)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:11,代码来源:test_rdq.py

示例7: testPuttingMoreThanWidthOnlyDispatchesWidth

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testPuttingMoreThanWidthOnlyDispatchesWidth(self):
     """
     Make sure that if we put 5 things onto a queue whose width is 3
     that shortly thereafter there are 3 jobs underway and 2 pending.
     """
     dq = ResizableDispatchQueue(self.slow, 3)
     for value in range(5):
         reactor.callLater(0.01, dq.put, value)
     yield task.deferLater(reactor, 0.1, self._testSize, dq, (3, 2))
     remaining = yield dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:12,代码来源:test_rdq.py

示例8: testSetWidthToZeroAfterInitiallyNonZeroThenStop

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testSetWidthToZeroAfterInitiallyNonZeroThenStop(self):
     """
     Make sure that a queue whose width is initially non-zero and which
     is then set to zero width returns all the added jobs when stopped.
     """
     dq = ResizableDispatchQueue(None, 3)
     dq.width = 0
     dq.put('aaa', 5)
     dq.put('bbb', 10)
     remaining = yield dq.stop()
     self.assertEqual(['aaa', 'bbb'], [job.jobarg for job in remaining])
开发者ID:jcollie,项目名称:txrdq,代码行数:13,代码来源:test_rdq.py

示例9: testNarrowWiden

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testNarrowWiden(self):
     """
     Create a queue of width 10. Narrowing to 7 means there will be 3
     pending stops, then widening to 8 will decrease the number of
     pending stops to 2.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 7
     self.assertEqual(dq.pendingStops, 3)
     dq.width = 8
     self.assertEqual(dq.pendingStops, 2)
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:14,代码来源:test_rdq.py

示例10: testUnstarted

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testUnstarted(self):
     """
     Check basic facts about a fresh instance of a
     ResizableDispatchQueue.
     """
     dq = ResizableDispatchQueue(None)
     self.assertEqual(dq.pending(), [])
     self.assertEqual(dq.underway(), set())
     self.assertFalse(dq.stopped)
     self.assertFalse(dq.paused)
     self.assertEqual((0, 0), dq.size())
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:14,代码来源:test_rdq.py

示例11: testSetWidthToZeroAfterInitiallyNonZero

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testSetWidthToZeroAfterInitiallyNonZero(self):
     """
     Make sure that a queue whose width is initially non-zero and which
     is then set to zero width does not then begin to process any added
     jobs.
     """
     dq = ResizableDispatchQueue(None, 3)
     dq.width = 0
     dq.put('aaa')
     dq.put('bbb')
     self.assertEqual((0, 2), dq.size())
     return dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:14,代码来源:test_rdq.py

示例12: testClearQueueCancelPending

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
    def testClearQueueCancelPending(self):
        """
        When the queue is cleared with cancelPending=True, the pending jobs
        should fail and receive a job whose state is CANCELLED.
        """
        def ok(result):
            self.fail('Unexpected success!')

        def checkCancel(failure):
            self.assertEqual(failure.value.state, Job.CANCELLED)

        dq = ResizableDispatchQueue(None, 2)
        dq.put(0).addCallbacks(ok, checkCancel)
        dq.put(1).addCallbacks(ok, checkCancel)
        self.assertEqual((0, 2), dq.size())
        dq.clearQueue(cancelPending=True)
        self.assertEqual((0, 0), dq.size())
        yield dq.stop()
开发者ID:jcollie,项目名称:txrdq,代码行数:20,代码来源:test_rdq.py

示例13: AdderCache

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]

#.........这里部分代码省略.........
        return d

    def cancel(self, screenname):
        log.msg('Attempting cancel of %r addition.' % screenname)
        try:
            user = self.users[screenname.lower()]
        except KeyError:
            raise Exception('Cannot cancel unknown user %r.' % screenname)
        else:
            if user.state == 'underway' or user.state == 'queued':
                for job in self.rdq.underway() + self.rdq.pending():
                    u = job.jobarg
                    if u.screenname == screenname:
                        log.msg('Cancelling %s %r addition.' %
                                (user.state, screenname))
                        job.cancel()
                        user.setState('canceled')
                        break
                else:
                    raise Exception('Could not find %r in underway '
                                    'or pending lists.' % screenname)
            else:
                user.setState('canceled')

    def added(self, screenname):
        try:
            user = self.users[screenname.lower()]
        except KeyError:
            return False
        else:
            return user.state == 'added'

    def known(self, screenname):
        return screenname.lower() in self.users

    def statusSummary(self, screennames):
        position = {}
        for i, user in enumerate(
            [job.jobarg for job in self.rdq.pending()]):
            position[user.screenname.lower()] = i
        queued = []
        underway = []
        added = []
        canceled = []
        failed = []
        unknown = []
        for screenname in screennames:
            try:
                user = self.users[screenname.lower()]
            except KeyError:
                unknown.append(screenname)
            else:
                log.msg('user: %s' % user)
                state = user.state

                if state == 'queued':
                    try:
                        pos = position[screenname.lower()]
                    except KeyError:
                        log.msg('ERROR: User %r has no queue position.' %
                                screenname)
                        pos = -1
                    queued.append([screenname, user.nFriends, pos])
                elif state == 'underway':
                    underway.append(
                        [screenname, user.nFriends,
                         float(user.workDone) / float(user.workToDo)])
                elif state == 'added':
                    added.append(screenname)
                elif state == 'canceled':
                    canceled.append(screenname)
                elif state == 'failed':
                    failed.append(screenname)
                else:
                    log.msg('ERROR: User %r is in an unknown state: %r' %
                            (screenname, state))

        return {
            'queued': queued,
            'underway': underway,
            'added': added,  # NB: 'added' is referred to in ftwitter.py
            'failed': failed,
            'canceled': canceled,
            'unknown': unknown,
            }

    @defer.inlineCallbacks
    def close(self):
        pending = yield self.rdq.stop()
        if pending:
            log.msg('Pending user additions canceled: %r' %
                    [p.screenname for p in pending])
        super(AdderCache, self).close()

    def _reportCancelled(self, fail, screenname):
        """
        A user addition was cancelled. Log it and absorb the failure.
        """
        fail.trap(defer.CancelledError)
        log.msg('Addition of user %r cancelled.' % screenname)
开发者ID:jkakar,项目名称:Tickery,代码行数:104,代码来源:adder.py

示例14: AdderCache

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]

#.........这里部分代码省略.........
        log.msg("User %r received from request queue." % user.screenname)
        user.setState("underway")
        d = ftwitter.addUserByScreenname(self.cache, self.endpoint, user)
        d.addCallbacks(_added, _failed)
        d.addErrback(log.err)
        return d

    def cancel(self, screenname):
        log.msg("Attempting cancel of %r addition." % screenname)
        try:
            user = self.users[screenname.lower()]
        except KeyError:
            raise Exception("Cannot cancel unknown user %r." % screenname)
        else:
            if user.state == "underway":
                for item in self.rdq.underway():
                    if item.job.screenname == screenname:
                        log.msg("Cancelling underway %r addition." % screenname)
                        item.cancel()
                        user.setState("canceled")
                        break
                else:
                    raise Exception("Could not find %r in underway list." % screenname)
            elif user.state == "queued":
                queued = self.rdq.pending()
                for i, u in enumerate(queued):
                    if u.screenname == screenname:
                        del queued[i]
                        user.setState("canceled")
                        log.msg("Canceled queued %r addition." % screenname)
                        break
                else:
                    raise Exception("Could not find %r in queued list." % screenname)
            else:
                user.setState("canceled")

    def added(self, screenname):
        try:
            user = self.users[screenname.lower()]
        except KeyError:
            return False
        else:
            return user.state == "added"

    def known(self, screenname):
        return screenname.lower() in self.users

    def statusSummary(self, screennames):
        position = {}
        for i, user in enumerate(self.rdq.pending()):
            position[user.screenname.lower()] = i
        log.msg("position dict is %r" % (position,))
        queued = []
        underway = []
        added = []
        canceled = []
        failed = []
        unknown = []
        for screenname in screennames:
            try:
                user = self.users[screenname.lower()]
            except KeyError:
                unknown.append(screenname)
            else:
                log.msg("user: %s" % user)
                state = user.state

                if state == "queued":
                    try:
                        pos = position[screenname.lower()]
                    except KeyError:
                        log.msg("ERROR: User %r has no queue position." % screenname)
                        pos = -1
                    queued.append([screenname, user.nFriends, pos])
                elif state == "underway":
                    underway.append([screenname, user.nFriends, float(user.workDone) / float(user.workToDo)])
                elif state == "added":
                    added.append(screenname)
                elif state == "canceled":
                    canceled.append(screenname)
                elif state == "failed":
                    failed.append(screenname)
                else:
                    log.msg("ERROR: User %r is in an unknown state: %r" % (screenname, state))

        return {
            "queued": queued,
            "underway": underway,
            "added": added,  # NB: 'added' is referred to in ftwitter.py
            "failed": failed,
            "canceled": canceled,
            "unknown": unknown,
        }

    @defer.inlineCallbacks
    def close(self):
        pending = yield self.rdq.stop()
        if pending:
            log.msg("Pending user additions canceled: %r" % [p.screenname for p in pending])
        super(AdderCache, self).close()
开发者ID:jdunck,项目名称:Tickery,代码行数:104,代码来源:adder.py

示例15: testStopAfterNoPuts

# 需要导入模块: from txrdq.rdq import ResizableDispatchQueue [as 别名]
# 或者: from txrdq.rdq.ResizableDispatchQueue import stop [as 别名]
 def testStopAfterNoPuts(self):
     dq = ResizableDispatchQueue(None, 5)
     pending = yield dq.stop()
     self.assertEqual(pending, [])
开发者ID:jcollie,项目名称:txrdq,代码行数:6,代码来源:test_rdq.py


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