From a99a9a447e809c280bc996b9ed6aba3c4a3a2360 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Dec 03 2019 14:11:24 +0000 Subject: Use a single thread pool while watching module builds Calling the Pool() constructor on each iteration leaks the threads, leading to a "can't start new thread" error during long waits. This can be aggravated by the constructor being called without an argument, which by default uses the systems CPU count to create the pool. When running in a container in a cloud environment this number can be unexpectedly large (for example, 64). Reuse the pool and limit the number of threads in the pool. Signed-off-by: Hunor Csomortáni --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 67cff94..ab0ad39 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3826,8 +3826,11 @@ class Commands(object): return stats def get_watched_module_builds(self, build_ids): + # Limit the number of threads to an arbitrary 8, + # to avoid starting too many threads when running in a + # container in the cloud. + pool = ThreadPool(min(8, len(build_ids) or 1)) while True: - pool = ThreadPool() module_builds = pool.map(self.module_get_build, build_ids) for module_build in module_builds: