Openembedded Devel Discussions
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Mike Looijmans <mike.looijmans@topic.nl>,
	openembedded-devel@lists.openembedded.org
Subject: Re: [PATCH 1/3] gitkpkgv: Ensure files are closed
Date: Tue, 07 Jun 2016 14:49:42 +0100	[thread overview]
Message-ID: <1465307382.13979.78.camel@linuxfoundation.org> (raw)
In-Reply-To: <57568DB8.6010209@topic.nl>

On Tue, 2016-06-07 at 11:02 +0200, Mike Looijmans wrote:
> Looks like regression in Python itself?
> 
> In both Python 2 and 3, the file is closed properly if the file
> object is not 
> being stored:
> 
>  >>> import os
>  >>> os.listdir('/proc/self/fd')
> ['0', '1', '2', '3']
>  >>> l=open('/proc/self/stat').readline()
>  >>> os.listdir('/proc/self/fd')
> ['0', '1', '2', '3']
>  >>> f=open('/proc/self/stat')
>  >>> os.listdir('/proc/self/fd')
> ['0', '1', '2', '3', '4']
>  >>>
> 
> 
> (file descriptor "3" is the one being used to read the /proc/self/fd 
> directory, "4" is the one used for reading the stat file)
> 
> The "with" construction should not be needed here. Something else is
> causing 
> this (e.g. nested function definition or exception handler?).

$ python2 -Wdefault -c "open('/bin/bash')"
$ python3 -Wdefault -c "open('/bin/bash')"
-c:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/bin/bash' mode='r' encoding='UTF-8'>

Admittedly its not an out the box warning but it is one that seems to
be enabled under bitbake. Details in:

https://bugs.python.org/issue10093

but the gist of the issue is that relying on the garbage collector to
close files is a cpython'ism and other implementations of python may
not do this.

So whilst "with" might not be strictly required, it is recommended.

Cheers,

Richard






  reply	other threads:[~2016-06-07 13:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02  9:34 [PATCH 1/3] gitkpkgv: Ensure files are closed Richard Purdie
2016-06-02  9:34 ` [PATCH 2/3] netmap-modules: Avoid type warning with python v3 Richard Purdie
2016-06-02  9:34 ` [PATCH 3/3] abiword/gnone-vfs: Use print as a function Richard Purdie
2016-06-07  9:02 ` [PATCH 1/3] gitkpkgv: Ensure files are closed Mike Looijmans
2016-06-07 13:49   ` Richard Purdie [this message]
2016-06-10  6:06     ` Mike Looijmans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465307382.13979.78.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=mike.looijmans@topic.nl \
    --cc=openembedded-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox