vmagamedov / grpclib

Pure-Python gRPC implementation for asyncio
http://grpclib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
922 stars 93 forks source link

Server doesn't stay open in Python 3.12 #182

Closed kochie closed 2 months ago

kochie commented 9 months ago

Due to changes in what I think is the asyncio library the example servers no longer stay running in Python 3.12. The server will successfully start but will immediately exit.

Changes can be found in the What's New for Python 3.12

The issue seems to be with server.wait_closed() as

server = Server([Health()])
with graceful_exit([server]):
    await server.start(port=port, ssl=context)
    print(f"Serving on {''}:{port}", flush=True)
    # await server.wait_closed()
    await asyncio.sleep(10)

print("Closing")

will wait for 10 seconds but

server = Server([Health()])
with graceful_exit([server]):
    await server.start(port=port, ssl=context)
    print(f"Serving on {''}:{port}", flush=True)
    await server.wait_closed()
    # await asyncio.sleep(10)

print("Closing")

Immediately closes

vmagamedov commented 8 months ago

Yes, Python 3.12 changed how asyncio:Server.wait_closed work, will release the fix soon

vmagamedov commented 8 months ago

Issued 0.4.7rc1 release candidate with Python 3.12 support added, please try it and tell if it solves your issue.

njooma commented 8 months ago

I'm not the original poster but I was facing the same issue -- the release candidate has seemed to fix it. Thanks for the quick turnaround!