async def run(name: str): logger.info("starting runner", name=name) bind(runner=name) for _ in range(10): wait = random.randrange(1, 15) / 10 logger.info("waiting for next message", now=time.time(), wait=wait) await nested() await asyncio.sleep(wait) logger.info("unbinding runner name") unbind("runner") logger.info("done")
def bench_async_context(loops, logger): # use fast local vars m = MSG_FORMAT_LONG_SIMPLE args = LONG_ARGS_SIMPLE range_loops = range(loops) t0 = pyperf.perf_counter() logctx.bind(testing=True, value="foo") for _ in range_loops: logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logger.warning(m, *args) logctx.clear() return pyperf.perf_counter() - t0
async def coro(): contextvars.bind(a=5, b="foo") contextvars.bind(b="bar", c=False) contextvars.merge(event)
async def coro(): contextvars.bind(a=5, b="foo", c=False) contextvars.clear() contextvars.merge(event)
async def coro(): contextvars.bind(a=5, c=True) contextvars.merge(event)
async def coro(): contextvars.bind(a=5) contextvars.unbind("a") contextvars.merge(event)
async def coro(): contextvars.bind(a=5, b="foo", c=False) contextvars.unbind("b") contextvars.merge(event)
async def coro3(): contextvars.bind(c=False) contextvars.merge(event)
async def coro2(): contextvars.bind(b="bar") await coro3()
async def coro1(): contextvars.bind(a=5) await coro2()