python / python/cpython

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

未關閉
#155,332 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

tests topic-multiprocessing
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/test/_test_multiprocessing.py 開始,檢查 test_imap_and_imap_unordered_when_buffer_is_full 和 test_imap_and_imap_unordered_with_buffersize_when_buffer_is_full。在不包含 ctypes 的建置上執行 test_multiprocessing_forkserver.test_threads;當兩個測試都避免出現 NameError 且測試執行通過時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
testing
Issue 類型
缺陷
難度
1/5
預估耗時
1 小時以內
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。