git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: "Luke Diamand" <luke@diamand.org>,
	"Git List" <git@vger.kernel.org>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Lars Schneider" <larsxschneider@gmail.com>,
	"Yang Zhao" <yang.zhao@skyboxlabs.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCHv1 4/6] git-p4: create helper function importRevisions()
Date: Thu, 30 Jan 2020 11:59:31 -0800	[thread overview]
Message-ID: <xmqqzhe4btr0.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CAPig+cRx3hG64nuDie69o_gdX39F=sR6D8LyA7J1rCErgu0aMA@mail.gmail.com> (Eric Sunshine's message of "Wed, 29 Jan 2020 10:00:29 -0500")

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Wed, Jan 29, 2020 at 6:13 AM Luke Diamand <luke@diamand.org> wrote:
>> This makes it easier to try/catch around this block of code to ensure
>> cleanup following p4 failures is handled properly.
>>
>> Signed-off-by: Luke Diamand <luke@diamand.org>
>> ---
>> diff --git a/git-p4.py b/git-p4.py
>> @@ -3555,6 +3555,73 @@ def importHeadRevision(self, revision):
>> +    def importRevisions(self, args, branch_arg_given):
>> +        if len(self.changesFile) > 0:
>> +            output = open(self.changesFile).readlines()
>
> Not a new problem (since this code is merely being relocated), but is
> this leaking the open file? Should there be an accompanying close()
> somewhere?
>
>     f = open(self.changesFile)
>     output = f.readlines()
>     close(f)
>
> or something.

Hmph, I was naively hoping that the (never assigned to any variable)
last reference going away at the end of the statement would make the
file object dead, and we can let eventual GC to close it.

Nevertheless it would not hurt to explicitly control the lifetime.

  parent reply	other threads:[~2020-01-30 19:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 11:12 [PATCHv1 0/6] git-p4: wait() for child processes better Luke Diamand
2020-01-29 11:12 ` [PATCHv1 1/6] git-p4: make closeStreams() idempotent Luke Diamand
2020-01-29 11:12   ` [PATCHv1 2/6] git-p4: add P4CommandException to report errors talking to Perforce Luke Diamand
2020-01-29 11:12     ` [PATCHv1 3/6] git-p4: disable some pylint warnings, to get pylint output to something manageable Luke Diamand
2020-01-29 11:12       ` [PATCHv1 4/6] git-p4: create helper function importRevisions() Luke Diamand
2020-01-29 11:12         ` [PATCHv1 5/6] git-p4: cleanup better on error exit Luke Diamand
2020-01-29 11:12           ` [PATCHv1 6/6] git-p4: check for access to remote host earlier Luke Diamand
2020-01-29 15:00         ` [PATCHv1 4/6] git-p4: create helper function importRevisions() Eric Sunshine
2020-01-29 18:36           ` Luke Diamand
2020-01-30 19:59           ` Junio C Hamano [this message]
2020-01-31 10:36             ` Luke Diamand
2020-01-30 10:52 ` [PATCHv1 0/6] git-p4: wait() for child processes better Johannes Schindelin
2020-01-30 11:33   ` Luke Diamand

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=xmqqzhe4btr0.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.org \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@gmail.com \
    --cc=yang.zhao@skyboxlabs.com \
    /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;
as well as URLs for NNTP newsgroup(s).