Added neat file example to imap docs.

This commit is contained in:
Ryan Williams
2010-03-16 22:42:54 -07:00
parent 6eafec482e
commit 18625a0fd6

View File

@@ -151,6 +151,14 @@ class GreenPool(object):
def imap(self, function, *iterables):
"""This is the same as :func:`itertools.imap`, and has the same
concurrency and memory behavior as :meth:`starmap`.
It's quite convenient for, e.g., farming out jobs from a file::
def worker(line):
return do_something(line)
pool = GreenPool()
for result in pool.imap(worker, open("filename", 'r')):
print result
"""
return self.starmap(function, itertools.izip(*iterables))