quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.28k stars 1.02k forks source link

Ignore spurious PollerCompletionQueue errors in AsyncioExecutor #6492

Open maffoo opened 8 months ago

maffoo commented 8 months ago

When using grpc with asyncio from multiple threads, spurious PollerCompletionQueue errors are printed due to multiple event loops listening a socket to be notified of grpc events. More than one event loop may be woken when the completion queue writes a byte to the notification socket, but only one of the loops receives the data and the others raise a BlockingIOError. This doesn't actually cause a problem in the grpc still works with asyncio in multiple threads, but lots of spurious error messages are printed by the default exception handler. (See https://github.com/grpc/grpc/issues/25364 for discussion of the issue.)

This configures the asyncio event loop used for grpc with an exception handler that ignores these BlockingIOErrors from the PollerCompletionQueue so that we don't spam the logs with scary-looking messages when using grpc with asyncio from multiple threads.

maffoo commented 8 months ago

Note: I filed https://github.com/grpc/grpc/pull/36096 to fix these errors upstream. We'll see what comes of that, but in any case it will be a while before we can rely on that and so I think silencing these errors in our own event loops makes sense.