Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_basic_cancel(self, channel):
async def callback(channel, body, envelope, _properties):
pass
queue_name = 'queue_name'
exchange_name = 'exchange_name'
await channel.queue_declare(queue_name)
await channel.exchange_declare(exchange_name, type_name='direct')
await channel.queue_bind(queue_name, exchange_name, routing_key='')
result = await channel.basic_consume(callback, queue_name=queue_name)
result = await channel.basic_cancel(result['consumer_tag'])
result = await channel.publish("payload", exchange_name, routing_key='')
await trio.sleep(1)
result = await channel.queue_declare(queue_name, passive=True)
assert result['message_count'] == 1
assert result['consumer_count'] == 0
async def sleep2():
nonlocal nhit
nhit += 1
await trio.sleep(TIMEOUT)
return False
async def send_indefinite_write_requests(self):
msg = self.write_req(
[], [(self.random_key(), self.random_value())], 0)
while True:
client = self.bft_network.random_client()
try:
await client.write(msg)
except:
pass
await trio.sleep(.1)
async def test_packer_processes_handshake_initiation(nursery,
packer,
enr,
remote_enr,
remote_endpoint,
incoming_packet_channels):
assert not packer.is_peer_packer_registered(remote_enr.node_id)
# receive packet
tag = compute_tag(source_node_id=remote_enr.node_id, destination_node_id=enr.node_id)
incoming_packet = IncomingPacket(
packet=AuthTagPacketFactory(tag=tag),
sender_endpoint=remote_endpoint,
)
await incoming_packet_channels[0].send(incoming_packet)
await trio.sleep(0)
assert packer.is_peer_packer_registered(remote_enr.node_id)
exposed_mods,
):
if actor_name:
async with tractor.find_actor(actor_name) as portal:
try:
await portal.run(__name__, func_name)
except tractor.RemoteActorError as err:
if not func_defined:
expect = AttributeError
if not exposed_mods:
expect = tractor.ModuleNotExposed
assert err.type is expect
raise
else:
await trio.sleep(float('inf'))
def _trio_init(lib: _AsyncLib):
import trio
from ._event_loop_wrappers import (trio_open_connection,
trio_send_all,
trio_receive_some,
trio_close,
trio_spawn)
lib.aopen = trio.open_file
lib.sleep = trio.sleep
lib.task_manager = trio.open_nursery
lib.timeout_after = AsyncWithWrapper.wrap(trio.fail_after)
lib.open_connection = trio_open_connection
lib.sendall = trio_send_all
lib.recv = trio_receive_some
lib.sock_close = trio_close
lib.spawn = trio_spawn
lib.cancel_task_group = _event_loop_wrappers.trio_cancel
lib.unwrap_taskgrouperror = lambda error: error.exceptions
lib.unwrap_result = lambda task: task.result.unwrap()
lib.Lock = trio.Lock
lib.Semaphore = trio.Semaphore
lib.Queue = trio.Queue
lib.Cancelled = trio.Cancelled
lib.Event = trio.Event
async def _call_at() -> None:
await trio.sleep(wait)
await func()
async def receive_all(self, length=1024, bsize=None):
buf = b''
bsize = bsize if bsize is not None else 1024
bsize = min(bsize, length)
received = 0
tries = 0
while received < length:
newbuf = await self.client_stream.receive_some(bsize)
if not newbuf:
# 3 successive read failure => raise exception
if tries > 3:
raise IOError('Unable to read full response')
tries += 1
trio.sleep(0.1)
continue
# reset counter
tries = 0
buf += newbuf
received += len(newbuf)
return buf
async def example():
async with qbroker.open_broker("example.send_alert", cfg=cfg) as _u:
global u
u = _u
await trio.sleep(0.2) # allow monitor to attach
async for r in u.alert(sys.argv[1], _data=json.loads(' '.join(sys.argv[2:])), timeout=3):
pprint(r.data)
async def getUAs():
global MAXNUMS
"""
爬行任务调度
"""
limit = trio.CapacityLimiter(LIMIT)
while TASKS:
MAXNUMS = len(list(TASKS))
loger.info(colored(f'当前任务量:{MAXNUMS}', 'red'))
await trio.sleep(1)
async with trio.open_nursery() as nursery:
for item in list(TASKS):
nursery.start_soon(getUAsitem, item, limit)