All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: <openembedded-devel@lists.openembedded.org>
Cc: Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: Re: [PATCH 1/3] gitkpkgv: Ensure files are closed
Date: Tue, 7 Jun 2016 11:02:48 +0200	[thread overview]
Message-ID: <57568DB8.6010209@topic.nl> (raw)
In-Reply-To: <1464860046-15121-1-git-send-email-richard.purdie@linuxfoundation.org>

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?).

Mike.


On 02-06-16 11:34, Richard Purdie wrote:
> This avoids warnings with python 3.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>   meta-oe/classes/gitpkgv.bbclass | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/meta-oe/classes/gitpkgv.bbclass b/meta-oe/classes/gitpkgv.bbclass
> index 1cba00c..4866fac 100644
> --- a/meta-oe/classes/gitpkgv.bbclass
> +++ b/meta-oe/classes/gitpkgv.bbclass
> @@ -87,11 +87,13 @@ def get_git_pkgv(d, use_tags):
>
>                       if commits != "":
>                           oe.path.remove(rev_file, recurse=False)
> -                        open(rev_file, "w").write("%d\n" % int(commits))
> +                        with open(rev_file, "w") as f:
> +                            f.write("%d\n" % int(commits))
>                       else:
>                           commits = "0"
>                   else:
> -                    commits = open(rev_file, "r").readline(128).strip()
> +                    with open(rev_file, "r") as f:
> +                        commits = f.readline(128).strip()
>
>                   if use_tags:
>                       try:
>



Kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products
Eindhovenseweg 32-C, NL-5683 KH Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: mike.looijmans@topicproducts.com
Website: www.topicproducts.com

Please consider the environment before printing this e-mail







  parent reply	other threads:[~2016-06-07 17:15 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 ` Mike Looijmans [this message]
2016-06-07 13:49   ` [PATCH 1/3] gitkpkgv: Ensure files are closed Richard Purdie
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=57568DB8.6010209@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=openembedded-devel@lists.openembedded.org \
    --cc=richard.purdie@linuxfoundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.