Commit b3e3099e authored by Denis Bilenko's avatar Denis Bilenko

fix issue #138: gevent.pool.Pool().imap_unordered hangs with an empty iterator (Thanks to exproxus)

parent 2a4a8aeb
......@@ -228,9 +228,13 @@ class IMapUnordered(Greenlet):
def _run(self):
try:
func = self.func
empty = True
for item in self.iterable:
self.count += 1
self.spawn(func, item).rawlink(self._on_result)
empty = False
if empty:
self.queue.put(Failure(StopIteration))
finally:
self.__dict__.pop('spawn', None)
self.__dict__.pop('func', None)
......@@ -288,6 +292,7 @@ class IMap(Greenlet):
def _run(self):
try:
empty = True
func = self.func
for item in self.iterable:
self.count += 1
......@@ -295,6 +300,10 @@ class IMap(Greenlet):
g.rawlink(self._on_result)
self.maxindex += 1
g.index = self.maxindex
empty = False
if empty:
self.maxindex += 1
self.queue.put((self.maxindex, Failure(StopIteration)))
finally:
self.__dict__.pop('spawn', None)
self.__dict__.pop('func', None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment