[PATCH] Don't try to iterate over threads directly in wait_all.

Vratislav Podzimek vpodzime at redhat.com
Fri Jul 17 09:33:27 UTC 2015


On Wed, 2015-07-08 at 11:06 -0400, Chris Lumens wrote:
> Someone may add or remove a thread mid-iteration, which causes a RuntimeError.
> Instead, grab a copy of all the thread names and then iterate over that.
> ---
>  pyanaconda/threads.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/pyanaconda/threads.py b/pyanaconda/threads.py
> index 8f52260..1e8082f 100644
> --- a/pyanaconda/threads.py
> +++ b/pyanaconda/threads.py
> @@ -120,7 +120,12 @@ class ThreadManager(object):
>      def wait_all(self):
>          """Wait for all threads to exit and if there was an error re-raise it.
>          """
> -        for name in self._objs.keys():
> +        names = []
> +
> +        with self._objs_lock:
> +            names = self._objs.keys()
> +
> +        for name in names:
>              if self.get(name) == threading.current_thread():
>                  continue
>              log.debug("Waiting for thread %s to exit", name)
This is definitely an improvement. I'm just not sure if we want/need to use the lock a little bit
more to prevent threads from being added when we are "waiting for all" as after calling this method,
there could still be some threads running (added after calling it).

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list