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.
This commit is contained in:
Gökçen Eraslan
2011-05-23 11:52:49 +00:00
parent 40e0f6617c
commit 21896fb32c
+28 -19
View File
@@ -113,17 +113,20 @@ class Index(xmlfile.XmlFile):
# have # have
pool = multiprocessing.Pool() pool = multiprocessing.Pool()
try: # Before calling pool.map check if list is empty or not: python#12157
# Add source packages to index using a process pool if specs:
self.specs = pool.map(add_spec, specs) try:
except: # Add source packages to index using a process pool
# If an exception occurs (like a keyboard interrupt), immediately self.specs = pool.map(add_spec, specs)
# terminate worker processes and propagate exception. (CLI honors except:
# KeyboardInterrupt exception, if you're not using CLI, you must # If an exception occurs (like a keyboard interrupt),
# handle KeyboardException yourself) # immediately terminate worker processes and propagate
# exception. (CLI honors KeyboardInterrupt exception, if you're
# not using CLI, you must handle KeyboardException yourself)
pool.terminate() pool.terminate()
raise pool.join()
raise
try: try:
obsoletes_list = map(str, self.distribution.obsoletes) obsoletes_list = map(str, self.distribution.obsoletes)
@@ -144,15 +147,21 @@ class Index(xmlfile.XmlFile):
latest_packages.append((pkg, deltas, repo_uri)) latest_packages.append((pkg, deltas, repo_uri))
try: # Before calling pool.map check if list is empty or not: python#12157
# Add binary packages to index using a process pool if latest_packages:
self.packages = pool.map(add_package, latest_packages) try:
except: # Add binary packages to index using a process pool
pool.terminate() self.packages = pool.map(add_package, latest_packages)
raise except:
else: pool.terminate()
# Clean up output pool.join()
ctx.ui.info("\r%-80.80s" % (_('Done.'))) raise
pool.close()
pool.join()
# Clean up output
ctx.ui.info("\r%-80.80s" % (_('Done.')))
def add_package(params): def add_package(params):
try: try: