Control: tags -1 + patch

This is not a bug in the individual python module packages as claimed at [1]. 
It is a bug in py3compile.

$ touch foo.py 
$ py3compile foo.py  
/usr/lib/python3.8/subprocess.py:838: RuntimeWarning: line buffering 
(buffering=1) isn't supported in binary mode, the default buffer size will be 
used 
 self.stdin = io.open(p2cwrite, 'wb', bufsize)

The origin is at the call to `Popen`, which provides fds in binary mode while 
`bufsize=1` implies line buffering which is only allowed with text mode [2, 3].

/usr/bin/py3compile:128
def py_compile(version, optimize, workers):
    if not isinstance(version, str):
        version = vrepr(version)
    cmd = "/usr/bin/python%s%s -m py_compile -" \
        % (version, ' -O' if optimize else '')
    process = Popen(cmd, bufsize=1, shell=True,
                    stdin=PIPE, close_fds=True)

The bug can be fixed by changing Popen to use text mode (`text=True`) but that 
risks encoding errors. Presumably the real desire here is just to have a buffer 
that is shorter than the default 8k for a binary fd and so changing bufsize to 
0 to disable buffering or indeed any other small integer would be OK.

The attached patch sets buffsize=0.

regards
Stuart

[1] https://bugs.launchpad.net/ubuntu/+source/python3.8/+bug/1863414

[2] https://docs.python.org/3/library/subprocess.html#subprocess.Popen

[3] https://docs.python.org/3/library/functions.html#open

-- 
Stuart Prescott    http://www.nanonanonano.net/   stu...@nanonanonano.net
Debian Developer   http://www.debian.org/         stu...@debian.org
GPG fingerprint    90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7
>From e05f2aa70feddca072c0315ee3ee3cd45f61e746 Mon Sep 17 00:00:00 2001
From: Stuart Prescott <stu...@debian.org>
Date: Thu, 5 Mar 2020 10:45:39 +1100
Subject: [PATCH] Use unbuffered IO to pass filenames to py_compile

Closes: #953056
---
 py3compile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/py3compile b/py3compile
index 125e6d3..f8e0c32 100755
--- a/py3compile
+++ b/py3compile
@@ -129,7 +129,7 @@ def py_compile(version, optimize, workers):
         version = vrepr(version)
     cmd = "/usr/bin/python%s%s -m py_compile -" \
         % (version, ' -O' if optimize else '')
-    process = Popen(cmd, bufsize=1, shell=True,
+    process = Popen(cmd, bufsize=0, shell=True,
                     stdin=PIPE, close_fds=True)
     workers[version] = process  # keep the reference for .communicate()
     stdin = process.stdin
-- 
2.20.1

Reply via email to