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():
context = aiomisc.get_context()
context['foo'] = True
await asyncio.sleep(0.1)
results.append(await context['foo'])
context['foo'] = False
await asyncio.sleep(0.1)
results.append(await context['foo'])
context['foo'] = None
await asyncio.sleep(0.1)
results.append(await context['foo'])
with aiomisc.entrypoint() as loop:
loop.run_until_complete(test())
assert results == [True, False, None]
@aiomisc.asyncbackoff(0.5, 0.5, 0, Exception, max_tries=max_tries)
async def test():
nonlocal mana
mana += 1
raise ValueError("RETRY")
@aiomisc.asyncbackoff(None, 1, 0, Exception)
async def test():
nonlocal mana
mana += 1
await asyncio.sleep(0.2)
raise ValueError("RETRY")
@aiomisc.asyncbackoff(0.15, None, 0, Exception)
async def test():
nonlocal mana
mana += 1
await asyncio.sleep(max_sleep - (mana - 1) * 0.1)
@aiomisc.asyncbackoff(0.10, 0.5)
async def test():
nonlocal mana
if mana < 500:
mana += 1
await asyncio.sleep(0.05)
raise ValueError("Not enough mana")
@aiomisc.asyncbackoff(0.10, 1, None, Exception)
async def test():
nonlocal mana
if mana < 5:
mana += 1
await asyncio.sleep(0.05)
raise ValueError("Not enough mana")
@aiomisc.asyncbackoff(0.5, 0.5, 0, Exception)
async def test():
nonlocal mana
if mana < 500:
mana += 1
await asyncio.sleep(5)
raise ValueError("Not enough mana")
@aiomisc.timeout(1)
async def test_select_cancel_true(loop: asyncio.AbstractEventLoop):
event1 = asyncio.Event()
event2 = asyncio.Event()
event3 = asyncio.Event()
async def coro1():
await event1.wait()
event2.set()
async def coro2():
await asyncio.sleep(0)
event3.set()
await aiomisc.select(coro2(), coro1(), cancel=True)
assert not event1.is_set()
assert not event2.is_set()
@aiomisc.timeout(1)
async def test_select_cancel_false(loop: asyncio.AbstractEventLoop):
event1 = asyncio.Event()
event2 = asyncio.Event()
event3 = asyncio.Event()
async def coro1():
await event1.wait()
event2.set()
async def coro2():
event1.set()
await event2.wait()
event3.set()
await aiomisc.select(coro2(), coro1(), cancel=False)
await event3.wait()
@aiomisc.timeout(0)
def test():
return