AioContext icon indicating copy to clipboard operation
AioContext copied to clipboard

Basic example gives an error

Open Valeronlol opened this issue 2 years ago • 0 comments

import asyncio
import aiocontext

context = aiocontext.Context()

async def print_request():
    print("Request ID:", context.get('request_id', 'unknown'))

async def handle_request():
    context['request_id'] = 42
    await print_request()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    aiocontext.wrap_task_factory(loop)
    context.attach(loop)
    loop.run_until_complete(handle_request())

AttributeError: type object '_asyncio.Task' has no attribute 'current_task' sys:1: RuntimeWarning: coroutine 'handle_request' was never awaited

Python version 3.10

Valeronlol avatar Jan 31 '23 13:01 Valeronlol