Python twisted.internet.defer.DeferredQueue() Examples
The following are 30
code examples of twisted.internet.defer.DeferredQueue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.defer
, or try the search function
.
Example #1
Source File: grpc_client.py From voltha with Apache License 2.0 | 6 votes |
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
Example #2
Source File: broadcom_onu.py From voltha with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: test_defer.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: test_defer.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #5
Source File: tlgs_onu.py From voltha with Apache License 2.0 | 6 votes |
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()
Example #6
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #7
Source File: test_event_bus.py From voltha with Apache License 2.0 | 6 votes |
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)
Example #8
Source File: pmcs_onu.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, adapter_agent, config): self.adapter_agent = adapter_agent self.config = config self.descriptor = Adapter( id=self.name, vendor='PMCS', version='0.1', config=AdapterConfig(log_level=LogLevel.INFO) ) self.incoming_messages = DeferredQueue() self.trangen = sequence_generator(1)
Example #9
Source File: rpc_dispatcher.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self): self.queue = DeferredQueue() # work in progress
Example #10
Source File: ponsim_onu.py From voltha with Apache License 2.0 | 5 votes |
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.proxy_address = None # reference of uni_port is required when re-enabling the device if # it was disabled previously self.uni_port = None self.pon_port = None
Example #11
Source File: dpoe_onu.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, adapter_agent, config): self.adapter_agent = adapter_agent self.config = config self.descriptor = Adapter( id=self.name, vendor='Sumitomo Electric, Inc.', version='0.1', config=AdapterConfig(log_level=LogLevel.INFO) ) self.incoming_messages = DeferredQueue()
Example #12
Source File: simulated_onu.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, adapter_agent, config): self.adapter_agent = adapter_agent self.config = config self.descriptor = Adapter( id=self.name, vendor='Voltha project', version='0.1', config=AdapterConfig(log_level=LogLevel.INFO) ) self.incoming_messages = DeferredQueue()
Example #13
Source File: chat.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self): reactor.listenTCP(24497, pb.PBServerFactory(self)) self.remote = None self.response_queue = DeferredQueue()
Example #14
Source File: maple_olt.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, device_id, adapter, onu_queue): self.device_id = device_id self.adapter = adapter self.onu_discovered_queue = onu_queue self.adapter_agent = adapter.adapter_agent self.adapter_name = adapter.name # registry('main').get_args().external_host_address self.pb_server_ip = '192.168.24.20' self.pb_server_port = 24497 self.pb_server_factory = pb.PBServerFactory(self) # start PB server self.listen_port = reactor.listenTCP(self.pb_server_port, self.pb_server_factory) self.omci_rx_queue = DeferredQueue() log.info('PB-server-started-on-port', port=self.pb_server_port)
Example #15
Source File: tibit_onu.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, adapter_agent, config): self.adapter_agent = adapter_agent self.config = config self.descriptor = Adapter( id=self.name, vendor='Tibit Communications Inc.', version='0.1', config=AdapterConfig(log_level=LogLevel.INFO) ) self.incoming_messages = DeferredQueue() self.mode = "GPON"
Example #16
Source File: tibit_olt.py From voltha with Apache License 2.0 | 5 votes |
def __init__(self, adapter_agent, config): self.adapter_agent = adapter_agent self.config = config self.descriptor = Adapter( id=self.name, vendor='Tibit Communications Inc.', version='0.1', config=AdapterConfig(log_level=LogLevel.INFO) ) self.interface = registry('main').get_args().interface self.io_port = None self.incoming_queues = {} # OLT mac_address -> DeferredQueue() self.device_ids = {} # OLT mac_address -> device_id self.vlan_to_device_ids = {} # c-vid -> (device_id, logical_device_id, mac_address) self.mode = "GPON"
Example #17
Source File: dbtasks.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self): """Initialise a new `DatabaseTasksService`.""" super().__init__() # Start with a queue that rejects puts. self.queue = DeferredQueue(size=0, backlog=1)
Example #18
Source File: microsemi_olt.py From voltha with Apache License 2.0 | 5 votes |
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()
Example #19
Source File: endpoints.py From afkak with Apache License 2.0 | 5 votes |
def connectionMade(self): self._log.debug("Connected") self.requests = defer.DeferredQueue(backlog=1)
Example #20
Source File: pubnub_twisted.py From jarvis with GNU General Public License v2.0 | 5 votes |
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)
Example #21
Source File: core.py From python-wpa-supplicant with Mozilla Public License 2.0 | 5 votes |
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)
Example #22
Source File: core.py From python-wpa-supplicant with Mozilla Public License 2.0 | 5 votes |
def __init__(self, reactor): defer.DeferredQueue.__init__(self) self._reactor = reactor
Example #23
Source File: test_defer.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
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()
Example #25
Source File: test_defer.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: test_defer.py From learn_python3_spider with MIT License | 5 votes |
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()
Example #27
Source File: test_defer.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #28
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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()
Example #29
Source File: test_defer.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)
Example #30
Source File: adtran_onu_handler.py From voltha with Apache License 2.0 | 4 votes |
def __init__(self, adapter, device_id): kwargs = dict() super(AdtranOnuHandler, self).__init__(**kwargs) self.adapter = adapter self.adapter_agent = adapter.adapter_agent self.device_id = device_id self.log = structlog.get_logger(device_id=device_id) self.logical_device_id = None self.proxy_address = None self._enabled = False self.pm_metrics = None self.alarms = None self._openomci = OMCI(self, adapter.omci_agent) self._in_sync_subscription = None self._pon_port_number = 1 self._unis = dict() # Port # -> UniPort self._pon = PonPort.create(self, self._pon_port_number) self._heartbeat = HeartBeat.create(self, device_id) self._deferred = None # Flow entries self._flows = dict() # OMCI resources # TODO: Some of these could be dynamically chosen self.vlan_tcis_1 = 0x900 self.mac_bridge_service_profile_entity_id = self.vlan_tcis_1 self.gal_enet_profile_entity_id = 0 # Technology profile related values self.incoming_messages = DeferredQueue() self.event_messages = DeferredQueue() self._tp_service_specific_task = dict() self._tech_profile_download_done = dict() # Initialize KV store client self.args = registry('main').get_args() if self.args.backend == 'etcd': host, port = self.args.etcd.split(':', 1) self.kv_client = EtcdStore(host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) elif self.args.backend == 'consul': host, port = self.args.consul.split(':', 1) self.kv_client = ConsulStore(host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX) else: self.log.error('Invalid-backend') raise Exception("Invalid-backend-for-kv-store") # Handle received ONU event messages reactor.callLater(0, self.handle_onu_events)