Ejemplo n.º 1
0
    async def _command_queue_loop(self):
        while True:
            try:
                command = await self.command_queue.get()
                self.circuit.process_command(command)
            except curio.TaskCancelled:
                break
            except Exception as ex:
                self.log.error('Command queue evaluation failed: {!r}'
                               ''.format(command),
                               exc_info=ex)
                continue

            if isinstance(command, (ca.ReadNotifyResponse, ca.ReadResponse,
                                    ca.WriteNotifyResponse)):
                user_event = self.ioids.pop(command.ioid)
                self.ioid_data[command.ioid] = command
                await user_event.set()
            elif isinstance(command, ca.EventAddResponse):
                user_queue = self.subscriptionids[command.subscriptionid]
                await user_queue.put(command)
            elif isinstance(command, ca.EventCancelResponse):
                self.subscriptionids.pop(command.subscriptionid)
            elif isinstance(command, ca.ErrorResponse):
                original_req = command.original_request
                cmd_class = ca.get_command_class(ca.CLIENT, original_req)
                if cmd_class in (ca.ReadNotifyRequest, ca.ReadRequest,
                                 ca.WriteNotifyRequest):
                    ioid = original_req.parameter2
                    user_event = self.ioids.pop(ioid)
                    self.ioid_data[ioid] = command
                    await user_event.set()
            async with self.new_command_condition:
                await self.new_command_condition.notify_all()
Ejemplo n.º 2
0
    async def _command_queue_loop(self):
        receiver = self.command_chan.receive
        while True:
            try:
                command = await receiver.receive()
                self.circuit.process_command(command)
            except Exception as ex:
                self.log.error('Command queue evaluation failed: {!r}'
                               ''.format(command),
                               exc_info=ex)
                continue

            if command is ca.DISCONNECTED:
                self.log.debug('Command queue loop exiting')
                break
            elif isinstance(command, (ca.ReadNotifyResponse, ca.ReadResponse,
                                      ca.WriteNotifyResponse)):
                user_event = self.ioids.pop(command.ioid)
                self.ioid_data[command.ioid] = command
                user_event.set()
            elif isinstance(command, ca.EventAddResponse):
                if command.subscriptionid in self.circuit.event_add_commands:
                    user_queue = self.subscriptionids[command.subscriptionid]
                    await user_queue.put(command)
                else:
                    self.subscriptionids.pop(command.subscriptionid)
            elif isinstance(command, ca.EventCancelResponse):
                self.subscriptionids.pop(command.subscriptionid)
            elif isinstance(command, ca.ErrorResponse):
                original_req = command.original_request
                cmd_class = ca.get_command_class(ca.CLIENT, original_req)
                if cmd_class in (ca.ReadNotifyRequest, ca.ReadRequest,
                                 ca.WriteNotifyRequest):
                    ioid = original_req.parameter2
                    user_event = self.ioids.pop(ioid)
                    self.ioid_data[ioid] = command
                    user_event.set()
            async with self.new_command_condition:
                self.new_command_condition.notify_all()