`$COLUMNS` environment variable present in subprocess only when `env=None`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
- Issue-Typ
- Bug
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- operating-systems
Rechercherichtung
Beginne mit dem minimalen subprocess.check_output-Beispiel und reproduziere alle vier Kombinationen aus interaktiver bzw. nicht interaktiver Ausführung und env=None bzw. env=os.environ. Verfolge die Handhabung der subprocess-Umgebung von diesem Einstiegspunkt aus; abgeschlossen ist die Aufgabe, wenn das unterschiedliche COLUMNS-Verhalten erklärt und entweder korrigiert oder mit einem entsprechenden Test eindeutig dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug report
for some reason which I cannot determine (perhaps a subtle difference between execvp and execvpe?) the $COLUMNS variable is mysteriously present in subprocesses when using env=None but not when using env=os.environ (which I expect to be identical in behaviour). this also seems to only happen with an interactive session?
here's a minimal case:
import sys, subprocess, os
subprocess.check_output(
(sys.executable, '-c', 'import os; print(os.environ["COLUMNS"])'),
# env=os.environ,
)
$ python3.11 -i t4.py
>>>
$ python3.11 t4.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<frozen os>", line 679, in __getitem__
KeyError: 'COLUMNS'
Traceback (most recent call last):
File "/home/asottile/workspace/cpython/t4.py", line 3, in <module>
subprocess.check_output(
File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('/usr/bin/python3.11', '-c', 'import os; print(os.environ["COLUMNS"])')' returned non-zero exit status 1.
if I un-comment the line in the example script above -- it fails in both places:
$ sed -i 's/#//g' -- t4.py
$ python3.11 -i t4.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<frozen os>", line 679, in __getitem__
KeyError: 'COLUMNS'
Traceback (most recent call last):
File "/home/asottile/workspace/cpython/t4.py", line 3, in <module>
subprocess.check_output(
File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('/usr/bin/python3.11', '-c', 'import os; print(os.environ["COLUMNS"])')' returned non-zero exit status 1.
>>>
$ python3.11 t4.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<frozen os>", line 679, in __getitem__
KeyError: 'COLUMNS'
Traceback (most recent call last):
File "/home/asottile/workspace/cpython/t4.py", line 3, in <module>
subprocess.check_output(
File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('/usr/bin/python3.11', '-c', 'import os; print(os.environ["COLUMNS"])')' returned non-zero exit status 1.
normally $COLUMNS is a shell variable and not an environment variable, but that doesn't really explain where it's coming from and why it's different depending both on interactiveness and on env= parameter:
| env=None | env=os.environ | |
|---|---|---|
| -i | ✔ | ❌ |
| ❌ | ❌ |
Your environment
- CPython versions tested on: 3.12a3, 3.11.1, 3.10.6
- Operating system and architecture: ubuntu 22.04, x86_64 -- I also tried in docker and it reproduces there as well -- kernel is
5.15.0-56-generic
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
docs pending
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
build type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
stdlib topic-email type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Ähnliche Issues
-
link-check link-check:sphinx-theme
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
OpenHands/extensions#626 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
CSCfi/sd-search-api#39 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100