`$COLUMNS` environment variable present in subprocess only when `env=None`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Bắt đầu với ví dụ subprocess.check_output tối thiểu và tái hiện cả bốn tổ hợp giữa thực thi tương tác và không tương tác, cùng env=None và env=os.environ. Theo dõi cách xử lý môi trường subprocess từ điểm vào đó; công việc được xem là hoàn tất khi hành vi khác nhau của COLUMNS được giải thích và được sửa hoặc được ghi tài liệu rõ ràng cùng với một bài kiểm thử tương ứng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100