-1

在我的一个模块中,我执行以下导入:

from multiprocessing import Pool

该模块在正常调用时工作正常,但是当我从单元测试中使用它时,出现以下错误:

Error
Traceback (most recent call last):
  File "/share/work/peter/software/lib/python3.2/unittest/case.py", line 387, in _executeTestPart
    function()
  File "/home/peter/current/parallelize/src/parallelize/backend/tests.py", line 52, in test_submit_ok_job
    backend = self._get_multi_processing_backend()
  File "/home/peter/current/parallelize/src/parallelize/backend/tests.py", line 46, in _get_multi_processing_backend
    from parallelize.backend.multiprocessing import MultiprocessingBackend
  File "/home/peter/current/parallelize/src/parallelize/backend/multiprocessing.py", line 2, in <module>
    from multiprocessing import Pool,cpu_count
  File "/home/peter/current/parallelize/src/parallelize/backend/multiprocessing.py", line 2, in <module>
    from multiprocessing import Pool,cpu_count
ImportError: cannot import name Pool

为什么会这样?我正在使用 Python 3.2

编辑我知道这只是从我的 PyCharm IDE 启动单元测试的情况。从命令行(python3 -m unittest ....)运行时,它可以工作。这是IDE中的错误吗?

4

1 回答 1

2

这可能是因为您...src/parallelize/backend/的 Python 路径上有目录(也许它是工作目录),而 Python 正试图Pool从您自己的multiprocessing.py那里导入,而不是从标准库中导入。我不知道 PyCharm 是否可行,但请尝试将工作目录更改为其他目录。

于 2011-07-14T09:44:39.113 回答