git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1 1/2] git-p4: print stderr if P4 read_pipe operation fails

From
Lars Schneider <larsxschneider@gmail.com>
Date
Sep 9, 2015, 18:50 UTC
Message-ID
<6A7A961A-9DB6-4B12-91E1-D6FE1F5E0358@gmail.com>
In-Reply-To
<xmqqbndb7fc0.fsf@gitster.mtv.corp.google.com>
On 09 Sep 2015, at 18:00, Junio C Hamano <gitster@pobox.com> wrote:
Show 39 quoted lines
> larsxschneider@gmail.com writes:
> 
>> From: Lars Schneider <larsxschneider@gmail.com>
>> 
>> If read_pipe crashes then the caller can inspect the error and handle
>> it appropriately.
>> 
>> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
>> ---
>> git-p4.py | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/git-p4.py b/git-p4.py
>> index 073f87b..36a4bcb 100755
>> --- a/git-p4.py
>> +++ b/git-p4.py
>> @@ -134,11 +134,11 @@ def read_pipe(c, ignore_error=False):
>>         sys.stderr.write('Reading pipe: %s\n' % str(c))
>> 
>>     expand = isinstance(c,basestring)
>> -    p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
>> +    p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
>>     pipe = p.stdout
>>     val = pipe.read()
>>     if p.wait() and not ignore_error:
>> -        die('Command failed: %s' % str(c))
>> +        die('Command failed: %s\nError: %s' % (str(c), p.stderr.read()))
> 
> I don't know enough about the callers of this helper function to
> tell offhand if that is an issue, but this looks unsafe depending on
> what the process on the other side of these pipes are doing.
> 
> If it attempts to spew a lot on its standard error stream first and
> then write some to its standard output, I would not be surprised it
> would get stuck waiting for us to read and drain its standard error
> before it can proceed to write to its standard output, and in the
> meantime we would be waiting for it to say something on its standard
> output, no?
> 

You are right. I will use the “communicate” function here as recommended in the Python docs: https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait

Thanks!
Previous: Junio C HamanoNext: larsxschneider@gmail.com
Message 4 of 5 in “git-p4: handle "Translation of file content failed"”
  1. 0/2 git-p4: handle "Translation of file content failed"larsxschneider@gmail.com, Sep 7, 2015
  2. 1/2 git-p4: print stderr if P4 read_pipe operation failslarsxschneider@gmail.com, Sep 7, 2015
  3. Junio C HamanoSep 9, 2015
  4. Lars SchneiderSep 9, 2015
  5. 2/2 git-p4: handle "Translation of file content failed"larsxschneider@gmail.com, Sep 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.