Re: [virt-bootstrap] [PATCH v6 05/26] get_mime_type: Properly close stdout handle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2017-08-17 at 10:39 +0100, Radostin Stoyanov wrote:
> This aims to fix the warning of Python3:
>     ResourceWarning: unclosed file <_io.BufferedReader name=3>
> ---
>  src/virtBootstrap/utils.py | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> index f98e0b3..fff7b35 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -176,12 +176,13 @@ def get_mime_type(path):
>      """
>          Get the mime type of a file.
>      """
> -    return (
> -        subprocess.Popen(
> -            ["/usr/bin/file", "--mime-type", path],
> -            stdout=subprocess.PIPE
> -        ).stdout.read().decode('utf-8').split()[1]
> +    proc = subprocess.Popen(
> +        ["/usr/bin/file", "--mime-type", path],
> +        stdout=subprocess.PIPE
>      )
> +    proc.wait()
> +    with proc.stdout as output:
> +        return output.read().decode('utf-8').split()[1]
>  
>  
>  def create_qcow2(tar_file, layer_file, backing_file=None, size=DEF_QCOW2_SIZE):

ACK

--
Cedric

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux