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,6 +629,9 @@ def run_in_parallel_local(func, args, unordered=False, ...@@ -629,6 +629,9 @@ 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
# 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" # Beware: we may not return "pool.imap" or "pool.imap_unordered"
# directly. It would somehow loose the focus and just hang infinitely. # directly. It would somehow loose the focus and just hang infinitely.
# Thus we wrap our own generator around it. # Thus we wrap our own generator around it.
...@@ -637,6 +640,8 @@ def run_in_parallel_local(func, args, unordered=False, ...@@ -637,6 +640,8 @@ def run_in_parallel_local(func, args, unordered=False,
# cancel requested # cancel requested
break break
yield result 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