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:
+14
-5
@@ -113,16 +113,19 @@ class Index(xmlfile.XmlFile):
|
|||||||
# have
|
# have
|
||||||
pool = multiprocessing.Pool()
|
pool = multiprocessing.Pool()
|
||||||
|
|
||||||
|
# Before calling pool.map check if list is empty or not: python#12157
|
||||||
|
if specs:
|
||||||
try:
|
try:
|
||||||
# Add source packages to index using a process pool
|
# Add source packages to index using a process pool
|
||||||
self.specs = pool.map(add_spec, specs)
|
self.specs = pool.map(add_spec, specs)
|
||||||
except:
|
except:
|
||||||
# If an exception occurs (like a keyboard interrupt), immediately
|
# If an exception occurs (like a keyboard interrupt),
|
||||||
# terminate worker processes and propagate exception. (CLI honors
|
# immediately terminate worker processes and propagate
|
||||||
# KeyboardInterrupt exception, if you're not using CLI, you must
|
# exception. (CLI honors KeyboardInterrupt exception, if you're
|
||||||
# handle KeyboardException yourself)
|
# not using CLI, you must handle KeyboardException yourself)
|
||||||
|
|
||||||
pool.terminate()
|
pool.terminate()
|
||||||
|
pool.join()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -144,13 +147,19 @@ class Index(xmlfile.XmlFile):
|
|||||||
|
|
||||||
latest_packages.append((pkg, deltas, repo_uri))
|
latest_packages.append((pkg, deltas, repo_uri))
|
||||||
|
|
||||||
|
# Before calling pool.map check if list is empty or not: python#12157
|
||||||
|
if latest_packages:
|
||||||
try:
|
try:
|
||||||
# Add binary packages to index using a process pool
|
# Add binary packages to index using a process pool
|
||||||
self.packages = pool.map(add_package, latest_packages)
|
self.packages = pool.map(add_package, latest_packages)
|
||||||
except:
|
except:
|
||||||
pool.terminate()
|
pool.terminate()
|
||||||
|
pool.join()
|
||||||
raise
|
raise
|
||||||
else:
|
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
|
|
||||||
# Clean up output
|
# Clean up output
|
||||||
ctx.ui.info("\r%-80.80s" % (_('Done.')))
|
ctx.ui.info("\r%-80.80s" % (_('Done.')))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user