Search code examples
pythonqueuegeventchannel

What is gevent.queue.Channel?


Under Gevent's what's new, a new class Channel under the gevent.queue module is mentioned:

Queue(0) is now equivalent to an unbound queue and raises DeprecationError. Use gevent.queue.Channel if you need a channel.

I checked the documentation page but there is no documentation about what Channel is or does. Looking at the source, it appears to be similar to Queue but it's not a subclass of it. What exactly is the purpose or use of Channel? Is it a specialized queue of some sort?


Solution

  • Looking at the code for the pre-1.0 version of Gevent tells you what a Channel is (though I recognize this is a bit convoluted):

    Queue(0) is a channel, that is, its put method always blocks until the item is delivered. (This is unlike the standard Queue, where 0 means infinite size).

    Now, as the release notes indicate, this behavior has changed in Gevent 1.0, and Queue(0) no longer works this way: Channel() does.

    You'll observe that, accordingly, the implementation of Channel.put is significantly more complex than that of Queue.put.

    Note that "standard Queue" refers to the standard library Queue.