Commit 131e25d6 authored by sumpfralle's avatar sumpfralle

fixed the memory leak under Python 2.7

* contributed by jferrara: http://sourceforge.net/projects/pycam/forums/forum/860184/topic/4753623


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1223 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b6602b5c
......@@ -629,14 +629,19 @@ def run_in_parallel_local(func, args, unordered=False,
imap_func = pool.imap_unordered
else:
imap_func = pool.imap
# Beware: we may not return "pool.imap" or "pool.imap_unordered"
# directly. It would somehow loose the focus and just hang infinitely.
# Thus we wrap our own generator around it.
for result in imap_func(func, args):
if callback and callback():
# cancel requested
break
yield result
# We need to use try/finally here to ensure the garbage collection
# of "pool". Otherwise a memory overflow is caused for Python 2.7.
try:
# Beware: we may not return "pool.imap" or "pool.imap_unordered"
# directly. It would somehow loose the focus and just hang infinitely.
# Thus we wrap our own generator around it.
for result in imap_func(func, args):
if callback and callback():
# cancel requested
break
yield result
finally:
pool.terminate()
else:
for arg in args:
if callback and callback():
......
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