pescador.mux.RoundRobinMux¶
- class pescador.mux.RoundRobinMux(streamers, mode='exhaustive', random_state=None)¶
A Mux which iterates over all streamers in strict order.
Based on the roundrobin() example in python itertools: https://docs.python.org/3/library/itertools.html#itertools-recipes
Examples
>>> a = pescador.Streamer("a") >>> b = pescador.Streamer("b") >>> c = pescador.Streamer("c") >>> mux = pescador.RoundRobinMux([a, b, c]) >>> print("".join(mux(max_iter=9))) "abc"
>>> mux = pescador.RoundRobinMux([a, b, c], mode="cycle") >>> print("".join(mux(max_iter=9))) "abcabcabc"
>>> mux = pescador.RoundRobinMux([a, b, c], mode="permuted_cycle") >>> print("".join(mux(max_iter=20))) "abcacbacbacbbcabacac"
- __init__(streamers, mode='exhaustive', random_state=None)¶
- Parameters:
- streamerslist of pescador.Streamers
- mode[“exhaustive”, “cycle”, “permuted_cycle”]
- exhaustive
RoundRobinMux
will exit after each stream has been exhausted.cycle
Restart streamer once all streams are exhausted.
- permuted_cycle
Restart streamer once streams are exhausted, and permute the order of the streams.
- random_stateNone, int, or
np.random.RandomState
If int, random_state is the seed used by the random number generator;
If RandomState instance, random_state is the random number generator;
If None, the random number generator is the RandomState instance used by
np.random.
Methods
__init__
(streamers[, mode, random_state])- Parameters:
cycle
([max_iter])Iterate from the streamer infinitely.
iterate
([max_iter])Yield items from the mux, and handle stream exhaustion and replacement.
Attributes
active
Return true if the stream is active (ie there are still open / existing streams)
is_activated_copy
is_activated_copy is true if this object is a copy of the original Streamer and has been activated.
n_streams
Return the number of streamers.