Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Let me break it down for you:

Suppose I run asyncio.start_server() and I want it to run forever. What am I supposed to asyncio.gather()) on without making stuff up?

[Edit] Production code or it didn't happen.



Given this:

    server = await asyncio.start_server(
            context.handle_requests, str(config.host), config.port, limit=MAX_READ_SIZE
        )
as stated, you can't use gather(). There are sleight of hand "coincidences", such as waiting on a watchdog which runs forever.

I stumbled on this as something that works:

    useless_lock = asyncio.Lock()
    while True:
        await useless_lock.acquire()
Which demonstrates that the following is, ahem, sleight of hand:

    async with server:
        await server.serve_forever()
although supposedly it guarantees some cleanup which I don't care about. Both options respond identically (at least with 3.11.0) to ^C.

I reiterate that serve_forever() is not in 3.6.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: