python - 调试时在 pool.close() 上抛出异常,但在运行时不会

标签 python pycharm python-multiprocessing

我不认为我在 Python 2.7 中遇到这个问题,但在 3.7 中调试时,Python 在调用 pool.close() 时抛出异常。这是函数的相关部分:

pool = multiprocessing.Pool(6)
iterator = pool.imap_unordered(worker_func, worker_input)

while True:
    try:
        t0, t1 = next(iterator)
    except multiprocessing.TimeoutError:
        continue
    except StopIteration:
        break
    else:
        dbinserts1(t0)
        dbinserts2(t1)            

pool.close()
pool.join()

2to3 所做的唯一更改是将 iterator.next() 重写为 next(iterator)。该函数仅在调试时失败(在 PyCharm 中),否则运行成功。这是(可能)堆栈跟踪中最相关的部分:

Error in atexit._run_exitfuncs: Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/util.py", line 322, in _exit_function p.join() File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 138, in join assert self._parent_pid == os.getpid(), 'can only join a child process'
AssertionError: can only join a child process

最佳答案

您使用哪个 PyCharm 版本?这似乎已在 2019.1.2 中由 https://youtrack.jetbrains.com/issue/PY-34436 修复

关于python - 调试时在 pool.close() 上抛出异常,但在运行时不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55929554/

相关文章:

python - 在 python 中使用 OpenCV 检测不完整形状的角

python - 取一系列列表的平均值并得到平均值

java - PyCharm 使用错误的文件路径

python - 使用 scikit-image 进行图像过滤?

python - 从 HTML 文档中提取 CSS 和 HTML 注释 (Python)

Pycharm:错误 "Cannot perform Refactoring. Function is not under the source root"

python - 将 JSON 对象发送到服务

python - 分析 python 多处理池

python-3.x - 如果 GPU 已经使用,Cupy 在 multithread.pool 中得到错误

python - 运行 Tornado 的多个实例会出现 ioloop is already running 错误