Hi Guido, Hi everyone, There's also another possible use case for your proposal, where you > actually have code that can either use asyncio or the threading queue > module in the same try/except block, and you'd like to catch both > exceptions. But this seems problematic, since you'd have to have a > yield-from in there, which would make the code a generator even if you were > using the threaded version. >
That is exactly the use case I am talking about. The only methods raising QueueFull or QueueEmpty (according to the docs) are get_nowait and put_nowait. Those happen not to be coroutines, so I don't need a yield from. This means I can use exactly the same code for queue.Queue and asyncio.Queue, if only the exceptions were the same... I'm actually writing a good-ole producer-consumer scheme, so a producer is putting in stuff into the queue using put_nowait, and a consumer consumes it later. The producer is coming from a library, and I am simply giving it an asyncio.Queue instead of a queue.Queue, and the library is all happy (yeah, duck typing rules!). Sure, I had to re-write the consumer using coroutines. All works fine, only when the producer is too fast, the queue fills up and I get an exception. And this is when things break. In principle, one could write an all-unified queue, which has get, get_nowait and get_async methods (and their put equivalents). I'm not sure whether that is a good idea. Greetings Martin