python / python/cpython

NameError: Value not defined in two threads-only pool tests when ctypes is unavailable

Đang mở
#155,332 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

tests topic-multiprocessing
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

In Lib/test/_test_multiprocessing.py, both
test_imap_and_imap_unordered_when_buffer_is_full and
test_imap_and_imap_unordered_with_buffersize_when_buffer_is_full create a
shared value with a module-level Value:

last_produced_task_arg = Value("i")

But Value is only conditionally imported at the top of the module:

try:
    from multiprocessing.sharedctypes import Value, copy
    HAS_SHAREDCTYPES = True
except ImportError:
    HAS_SHAREDCTYPES = False

So when ctypes/sharedctypes are unavailable (HAS_SHAREDCTYPES == False), the
name Value is undefined. Unlike the other sharedctypes-based tests in this
file (which use @unittest.skipUnless(HAS_SHAREDCTYPES, ...)), these two tests
have no such guard, so they run and raise:

NameError: name 'Value' is not defined. Did you mean: 'self.Value'?

Reproduced in verbose mode as 4 errors (2 tests x {imap, imap_unordered})
when running test_multiprocessing_forkserver.test_threads on a build without
ctypes.

These tests are threads-only (they call skipTest() for other backends), so
self.Value resolves to multiprocessing.dummy.Value and does not depend on
ctypes. Replacing Value("i") with self.Value("i", 0):

  • fixes the NameError on builds without ctypes, and
  • matches how the rest of the suite creates shared values. Since both
    forms initialize the value to zero, there is no behavior change when
    ctypes is available.

Proposed fix:

- last_produced_task_arg = Value("i")
+ last_produced_task_arg = self.Value("i", 0)

This is my first contribution to CPython. I used Claude and opencode to help
me understand the codebase, and vim to edit the file. I reviewed and tested
the change myself; please let me know if I missed any process step

Linked PRs
  • gh-155333

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Lib/test/_test_multiprocessing.py và kiểm tra test_imap_and_imap_unordered_when_buffer_is_full cùng test_imap_and_imap_unordered_with_buffersize_when_buffer_is_full. Chạy test_multiprocessing_forkserver.test_threads trên một bản build không có ctypes; hoàn thành khi cả hai test đều không gặp NameError và lần chạy test thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.