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