Class fq
source code
object --+
|
fq
I'm a simple round-robin fair queue. I'm like a regular channel, except
that when users L{put} an element into me, the element is associated with a
key (which represents an "input source"). When user later L{get} from me, I
pick elements from each of my keys in round-robin fashion, in the order in
which they were inserted. This way, each input source effectively gets its
own queue, and I can dequeue from the multiple input sources fairly.
q = fq( 10 )
yield q.put('user 1', 'packet 1')
yield q.put('user 1', 'packet 2')
yield q.put('user 1', 'packet 3')
yield q.put('user 2', 'packet 4')
yield q.put('user 2', 'packet 5')
yield q.put('user 2', 'packet 6')
while True:
packet = yield q.get()
yield send( packet ) # send packets 1, 4, 2, 5, 3, 6
|
|
|
|
|
|
|
|
|
|
|
|
|
Inherited from object:
__delattr__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__str__
|
|
Inherited from object:
__class__
|
Initializer.
- Parameters:
n (int) - maximum size of this queue, or None for infinite
- Overrides:
object.__init__
|