ACK: [kteam-tools PATCH] ktl/shell: always wait for thread to finish
Colin Ian King
colin.king at canonical.com
Wed Apr 26 13:48:35 UTC 2017
On 26/04/17 14:44, Thadeu Lima de Souza Cascardo wrote:
> link-to-tracker was failing many times when getting the current branch,
> because the output of the git command was empty. In fact, this popen
> wrapper was not waiting for the command to finish, subject to race
> conditions.
>
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo at canonical.com>
> ---
> ktl/shell.py | 4 ++++
> ktl3/shell.py | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/ktl/shell.py b/ktl/shell.py
> index ba5999eb..19d142cc 100644
> --- a/ktl/shell.py
> +++ b/ktl/shell.py
> @@ -88,6 +88,10 @@ def sh(cmd, timeout=None, ignore_result=False, quiet=False):
> if t.is_alive():
> p.terminate()
> raise ShellTimeoutError(cmd, timeout)
> + else:
> + # If a timeout has not been specified, we still need to wait for
> + # the thread to finish, but just don't care how long we wait.
> + t.join()
>
> while p.poll() is None:
> # read line without blocking
> diff --git a/ktl3/shell.py b/ktl3/shell.py
> index 7d70e5c3..72f21052 100644
> --- a/ktl3/shell.py
> +++ b/ktl3/shell.py
> @@ -97,6 +97,10 @@ def sh(cmd, timeout=None, ignore_result=False, quiet=False):
> p.terminate()
> cleave("sh")
> raise ShellTimeoutError(cmd, timeout)
> + else:
> + # If a timeout has not been specified, we still need to wait for
> + # the thread to finish, but just don't care how long we wait.
> + t.join()
>
> while p.poll() is None:
> # read line without blocking
>
Yep, makes sense and avoiding races is paramount.
Acked-by: Colin Ian King <colin.king at canonical.com>
More information about the kernel-team
mailing list