Patchwork [3,of,4] py3: fully detach TextIOWrapper

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 4, 2017, 2:53 p.m.
Message ID <fecbf1e8aa17474f448e.1507128836@mimosa>
Download mbox | patch
Permalink /patch/24493/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 4, 2017, 2:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506923984 -3600
#      Mon Oct 02 06:59:44 2017 +0100
# Node ID fecbf1e8aa17474f448e126697fe287e44c92664
# Parent  2b071e9303f748de41c02efdea158883d336224a
py3: fully detach TextIOWrapper

This silences the following error message in test-basic.t, which would
probably be caused by the last-minute flush() run in __del__.

  $ hg status >/dev/full
  abort: No space left on devic
  Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='ANSI_X3.4-1968'>
  OSError: [Errno 28] No space left on device

Since sys.std* files are completely reimplemented in Python 3, we wouldn't
need the setbinary() hack, so replaced it.
Yuya Nishihara - Oct. 10, 2017, 2:20 p.m.
On Wed, 04 Oct 2017 23:53:56 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1506923984 -3600
> #      Mon Oct 02 06:59:44 2017 +0100
> # Node ID fecbf1e8aa17474f448e126697fe287e44c92664
> # Parent  2b071e9303f748de41c02efdea158883d336224a
> py3: fully detach TextIOWrapper

Unfortunately, this broke test-py3-commands.t and it seems the Python
interpreter really hates detaching TextIOWrapper from stdio. So I'm going
to drop this and the next patch.
Augie Fackler - Oct. 10, 2017, 2:36 p.m.
> On Oct 10, 2017, at 10:20, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> On Wed, 04 Oct 2017 23:53:56 +0900, Yuya Nishihara wrote:
>> # HG changeset patch
>> # User Yuya Nishihara <yuya@tcha.org>
>> # Date 1506923984 -3600
>> #      Mon Oct 02 06:59:44 2017 +0100
>> # Node ID fecbf1e8aa17474f448e126697fe287e44c92664
>> # Parent  2b071e9303f748de41c02efdea158883d336224a
>> py3: fully detach TextIOWrapper
> 
> Unfortunately, this broke test-py3-commands.t and it seems the Python
> interpreter really hates detaching TextIOWrapper from stdio. So I'm going
> to drop this and the next patch.

Ugh, python3. Thanks.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -96,9 +96,15 @@  def run():
         req.ui.ferr.flush()
     sys.exit(status & 255)
 
-def _initstdio():
-    for fp in (sys.stdin, sys.stdout, sys.stderr):
-        util.setbinary(fp)
+if pycompat.ispy3:
+    def _initstdio():
+        # detach wrapper so it will never flush() underlying IO implicitly
+        for fp in (sys.stdin, sys.stdout, sys.stderr):
+            fp.detach()
+else:
+    def _initstdio():
+        for fp in (sys.stdin, sys.stdout, sys.stderr):
+            util.setbinary(fp)
 
 def _getsimilar(symbols, value):
     sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()