Multi thread reading a file
ryles
rylesny at gmail.com
Fri Jul 3 00:13:19 EDT 2009
On Jul 2, 11:55 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Yeah, it should allow supplying a predicate instead of using == on
> a value. How about (untested):
>
> from itertools import *
> ...
> for row in takewhile(lambda x: x is sentinel,
> starmap(in_queue.get, repeat(()))):
> ...
Yeah, it's a small recipe I'm sure a lot of others have written as
well. My old version:
def iterwhile(callable_, predicate):
""" Like iter() but with a predicate instead of a sentinel. """
return itertools.takewhile(predicate, repeatfunc(callable_))
where repeatfunc is as defined here:
http://docs.python.org/library/itertools.html#recipes
I wish all of these little recipes made their way into itertools or a
like module; itertools seems a bit tightly guarded.
More information about the Python-list
mailing list