grpclib
grpclib copied to clipboard
Server doesn't stay open in Python 3.12
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
Yes, Python 3.12 changed how asyncio:Server.wait_closed work, will release the fix soon
Issued 0.4.7rc1 release candidate with Python 3.12 support added, please try it and tell if it solves your issue.
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!