本文整理汇总了Python中curio.CancelledError方法的典型用法代码示例。如果您正苦于以下问题:Python curio.CancelledError方法的具体用法?Python curio.CancelledError怎么用?Python curio.CancelledError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curio
的用法示例。
在下文中一共展示了curio.CancelledError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: relay_udp
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def relay_udp(self, sock):
while True:
try:
data, addr = await sock.recvfrom(8192)
print(data, addr, self.taddr)
if addr == self.taddr:
taddr, data = unpack_addr(data, 3)
address = taddr
else:
address = self.taddr
while data:
nbytes = await sock.sendto(data, address)
data = data[nbytes:]
except CancelledError:
return
except Exception as e:
if verbose > 0:
print(f"{self} error: {e}")
if verbose > 1:
traceback.print_exc()
示例2: _relay
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def _relay(self, addr, listen_addr, sendfunc):
try:
while True:
data, _ = await self.sock.recvfrom(8192)
payload, taddr = self._unpack(data)
if verbose > 0:
print(
f"udp: {addr[0]}:{addr[1]} <-- "
f"{listen_addr[0]}:{listen_addr[1]} <-- "
f"{self.raddr[0]}:{self.raddr[1]} <-- "
f"{self.taddr[0]}:{self.taddr[1]}"
)
if sendfunc is None:
await sendto_from(self.taddr, payload, addr)
else:
await sendfunc(payload, addr)
except CancelledError:
pass
示例3: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def run(self):
try:
while True:
msg = await self.q.get()
msg_type, hub, msg_val = msg
await self.q.task_done()
self.message_debug(f'Got msg: {msg_type} = {msg_val}')
await self.send_message(hub.tx, msg_val)
except CancelledError:
self.message(f'Terminating and disconnecxting')
if USE_BLEAK:
await self.ble.in_queue.put( 'quit' )
else:
self.device.disconnect()
示例4: spin
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def spin(msg): # <1>
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/-\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
try:
await curio.sleep(.1) # <2>
except curio.CancelledError: # <3>
break
write(' ' * len(status) + '\x08' * len(status))
示例5: relay
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def relay(self, remote_stream):
t1 = await spawn(self._relay(self._stream, remote_stream))
t2 = await spawn(self._relay2(remote_stream, self._stream))
try:
async with TaskGroup([t1, t2]) as g:
task = await g.next_done()
await task.join()
await g.cancel_remaining()
except CancelledError:
pass
示例6: peripheral_message_loop
# 需要导入模块: import curio [as 别名]
# 或者: from curio import CancelledError [as 别名]
def peripheral_message_loop(self):
"""The main loop that receives messages from the :class:`bricknil.messages.Message` parser.
Waits for messages on a UniversalQueue and dispatches to the appropriate peripheral handler.
"""
try:
self.message_debug(f'starting peripheral message loop')
# Check if we have any hub button peripherals attached
# - If so, we need to manually call peripheral.activate_updates()
# - and then register the proper handler inside the message parser
while True:
msg = await self.peripheral_queue.get()
msg, data = msg
await self.peripheral_queue.task_done()
if msg == 'value_change':
port, msg_bytes = data
peripheral = self.port_to_peripheral[port]
await peripheral.update_value(msg_bytes)
self.message_debug(f'peripheral msg: {peripheral} {msg}')
if self.web_queue_out:
cls_name = peripheral.__class__.__name__
if len(peripheral.capabilities) > 0:
for cap in peripheral.value:
await self.web_message.send(peripheral, f'value change mode: {cap.value} = {peripheral.value[cap]}')
#await self.web_queue_out.put( f'{self.name}|{cls_name}|{peripheral.name}|{peripheral.port}|value change mode: {cap.value} = {peripheral.value[cap]}\r\n'.encode('utf-8') )
handler_name = f'{peripheral.name}_change'
handler = getattr(self, handler_name)
await handler()
elif msg == 'attach':
port, device_name = data
peripheral = await self.connect_peripheral_to_port(device_name, port)
if peripheral:
self.message_debug(f'peripheral msg: {peripheral} {msg}')
peripheral.message_handler = self.send_message
await peripheral.activate_updates()
elif msg == 'update_port':
port, info = data
self.port_info[port] = info
elif msg.startswith('port'):
port = data
if self.query_port_info:
await self._get_port_info(port, msg)
else:
raise UnknownPeripheralMessage
except CancelledError:
self.message(f'Terminating peripheral')