From 21896fb32c97f0c1c7bf6ad39ba5b30c14abcccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6k=C3=A7en=20Eraslan?= Date: Mon, 23 May 2011 11:52:49 +0000 Subject: [PATCH] index: Make sure that pool is safely closed and joined. Make sure we call close and join methods of Pool object properly in any case. This fixes hundreds of processes appeard in buildfarm. --- pisi/index.py | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/pisi/index.py b/pisi/index.py index e151cdb6..c9a56653 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -113,17 +113,20 @@ class Index(xmlfile.XmlFile): # have pool = multiprocessing.Pool() - try: - # Add source packages to index using a process pool - self.specs = pool.map(add_spec, specs) - except: - # If an exception occurs (like a keyboard interrupt), immediately - # terminate worker processes and propagate exception. (CLI honors - # KeyboardInterrupt exception, if you're not using CLI, you must - # handle KeyboardException yourself) + # Before calling pool.map check if list is empty or not: python#12157 + if specs: + try: + # Add source packages to index using a process pool + self.specs = pool.map(add_spec, specs) + except: + # If an exception occurs (like a keyboard interrupt), + # immediately terminate worker processes and propagate + # exception. (CLI honors KeyboardInterrupt exception, if you're + # not using CLI, you must handle KeyboardException yourself) - pool.terminate() - raise + pool.terminate() + pool.join() + raise try: obsoletes_list = map(str, self.distribution.obsoletes) @@ -144,15 +147,21 @@ class Index(xmlfile.XmlFile): latest_packages.append((pkg, deltas, repo_uri)) - try: - # Add binary packages to index using a process pool - self.packages = pool.map(add_package, latest_packages) - except: - pool.terminate() - raise - else: - # Clean up output - ctx.ui.info("\r%-80.80s" % (_('Done.'))) + # Before calling pool.map check if list is empty or not: python#12157 + if latest_packages: + try: + # Add binary packages to index using a process pool + self.packages = pool.map(add_package, latest_packages) + except: + pool.terminate() + pool.join() + raise + + pool.close() + pool.join() + + # Clean up output + ctx.ui.info("\r%-80.80s" % (_('Done.'))) def add_package(params): try: