本文整理汇总了Python中twisted.internet.defer.DeferredQueue方法的典型用法代码示例。如果您正苦于以下问题:Python defer.DeferredQueue方法的具体用法?Python defer.DeferredQueue怎么用?Python defer.DeferredQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.defer
的用法示例。
在下文中一共展示了defer.DeferredQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cancelQueueAfterGet
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def test_cancelQueueAfterGet(self):
"""
When canceling a L{Deferred} from a L{DeferredQueue} that does not
have a result (i.e., the L{Deferred} has not fired), the cancel
causes a L{defer.CancelledError} failure. If the queue has a result
later on, it doesn't try to fire the deferred.
"""
queue = defer.DeferredQueue()
d = queue.get()
d.cancel()
self.assertImmediateFailure(d, defer.CancelledError)
def cb(ignore):
# If the deferred is still linked with the deferred queue, it will
# fail with an AlreadyCalledError
queue.put(None)
return queue.get().addCallback(self.assertIs, None)
d.addCallback(cb)
done = []
d.addCallback(done.append)
self.assertEqual(len(done), 1)
示例2: test_cancelQueueAfterGet
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def test_cancelQueueAfterGet(self):
"""
When canceling a L{Deferred} from a L{DeferredQueue} that does not
have a result (i.e., the L{Deferred} has not fired), the cancel
causes a L{defer.CancelledError} failure. If the queue has a result
later on, it doesn't try to fire the deferred.
"""
queue = defer.DeferredQueue()
d = queue.get()
self.assertFailure(d, defer.CancelledError)
d.cancel()
def cb(ignore):
# If the deferred is still linked with the deferred queue, it will
# fail with an AlreadyCalledError
queue.put(None)
return queue.get().addCallback(self.assertIdentical, None)
return d.addCallback(cb)
示例3: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, adapter, device_id):
self.adapter = adapter
self.adapter_agent = adapter.adapter_agent
self.device_id = device_id
self.log = structlog.get_logger(device_id=device_id)
self.incoming_messages = DeferredQueue()
self.event_messages = DeferredQueue()
self.proxy_address = None
self.tx_id = 0
self.flow_map = dict()
# Need to query ONU for number of supported uni ports
# For now, temporarily set number of ports to 1 - port #2
self.uni_ports = (1, 2, 3, 4, 5)
self.flow_config_in_progress = False
# Handle received ONU event messages
reactor.callLater(0, self.handle_onu_events)
示例4: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, adapter, device_id):
self.adapter = adapter
self.adapter_agent = adapter.adapter_agent
self.device_id = device_id
self.log = structlog.get_logger(device_id=device_id)
#self.incoming_messages = Queue.Queue()
self.incoming_messages = DeferredQueue()
self.event_messages = Queue.Queue()
self.proxy_address = None
self.tx_id = 0
self.trangen = sequence_generator(1)
self.port_id = None
self.alloc_id = None
self.cvlan_id = None
self.subsvlan_id = None
self.bandwidth = None
self.flows_lock = 0
self.flows = None
self.policy_id = None
self.flow_queue = DeferredQueue()
示例5: test_deferred_queue_receiver
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def test_deferred_queue_receiver(self):
ebc = EventBus()
queue = DeferredQueue()
ebc.subscribe('', lambda _, msg: queue.put(msg))
for i in xrange(10):
ebc.publish('', i)
self.assertEqual(len(queue.pending), 10)
for i in xrange(10):
msg = yield queue.get()
self.assertEqual(msg, i)
self.assertEqual(len(queue.pending), 0)
示例6: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, connection_manager, channel, grpc_timeout):
self.log = get_logger()
self.connection_manager = connection_manager
self.channel = channel
self.grpc_timeout = grpc_timeout
self.local_stub = VolthaLocalServiceStub(channel)
self.stopped = False
self.packet_out_queue = Queue() # queue to send out PacketOut msgs
self.packet_in_queue = DeferredQueue() # queue to receive PacketIn
self.change_event_queue = DeferredQueue() # queue change events
self.count_pkt_in = 0
self.count_pkt_out = 0
示例7: connectionMade
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def connectionMade(self):
self._log.debug("Connected")
self.requests = defer.DeferredQueue(backlog=1)
示例8: testQueue
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def testQueue(self):
N, M = 2, 2
queue = defer.DeferredQueue(N, M)
gotten = []
for i in range(M):
queue.get().addCallback(gotten.append)
self.assertRaises(defer.QueueUnderflow, queue.get)
for i in range(M):
queue.put(i)
self.assertEqual(gotten, list(range(i + 1)))
for i in range(N):
queue.put(N + i)
self.assertEqual(gotten, list(range(M)))
self.assertRaises(defer.QueueOverflow, queue.put, None)
gotten = []
for i in range(N):
queue.get().addCallback(gotten.append)
self.assertEqual(gotten, list(range(N, N + i + 1)))
queue = defer.DeferredQueue()
gotten = []
for i in range(N):
queue.get().addCallback(gotten.append)
for i in range(N):
queue.put(i)
self.assertEqual(gotten, list(range(N)))
queue = defer.DeferredQueue(size=0)
self.assertRaises(defer.QueueOverflow, queue.put, None)
queue = defer.DeferredQueue(backlog=0)
self.assertRaises(defer.QueueUnderflow, queue.get)
示例9: test_cancelQueueAfterSynchronousGet
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def test_cancelQueueAfterSynchronousGet(self):
"""
When canceling a L{Deferred} from a L{DeferredQueue} that already has
a result, the cancel should have no effect.
"""
def _failOnErrback(_):
self.fail("Unexpected errback call!")
queue = defer.DeferredQueue()
d = queue.get()
d.addErrback(_failOnErrback)
queue.put(None)
d.cancel()
示例10: testQueue
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def testQueue(self):
N, M = 2, 2
queue = defer.DeferredQueue(N, M)
gotten = []
for i in range(M):
queue.get().addCallback(gotten.append)
self.assertRaises(defer.QueueUnderflow, queue.get)
for i in range(M):
queue.put(i)
self.assertEquals(gotten, range(i + 1))
for i in range(N):
queue.put(N + i)
self.assertEquals(gotten, range(M))
self.assertRaises(defer.QueueOverflow, queue.put, None)
gotten = []
for i in range(N):
queue.get().addCallback(gotten.append)
self.assertEquals(gotten, range(N, N + i + 1))
queue = defer.DeferredQueue()
gotten = []
for i in range(N):
queue.get().addCallback(gotten.append)
for i in range(N):
queue.put(i)
self.assertEquals(gotten, range(N))
queue = defer.DeferredQueue(size=0)
self.assertRaises(defer.QueueOverflow, queue.put, None)
queue = defer.DeferredQueue(backlog=0)
self.assertRaises(defer.QueueUnderflow, queue.get)
示例11: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, reactor):
defer.DeferredQueue.__init__(self)
self._reactor = reactor
示例12: get
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def get(self, timeout=None):
"""Synchronously get the result of :meth:`defer.DeferredQueue.get()`
:param timeout: optional timeout parameter (integer # of sections)
:returns: The result value that has been put onto the deferred queue
:raises MethodTimeout: More time has elapsed than the specified `timeout`
"""
deferred = defer.DeferredQueue.get(self)
if timeout:
call_id = self._reactor.callLater(timeout, self._timed_out, deferred)
deferred.addCallback(self._stop_timeout, call_id)
return _eval(deferred, self._reactor)
示例13: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, pubnub_instance):
self._message_queue = DeferredQueue()
self.worker_loop = None
self._heartbeat_loop = None
self._heartbeat_call = None
self.clock = pubnub_instance.clock
super(TwistedSubscriptionManager, self).__init__(pubnub_instance)
示例14: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self):
"""Initialise a new `DatabaseTasksService`."""
super().__init__()
# Start with a queue that rejects puts.
self.queue = DeferredQueue(size=0, backlog=1)
示例15: __init__
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import DeferredQueue [as 别名]
def __init__(self, adaptor_agent, config, descriptor):
self.adaptor_agent = adaptor_agent
self.config = config
self.descriptor = descriptor
self.device = None
self.device_manager = None
self.comm = None
self.activation = None
self.olt = None
self.ports = dict()
self.last_iteration_ports = []
self.interface = registry('main').get_args().interface
self.flow_queue = DeferredQueue()