如何在pycharm中省略pytest中的“--multiprocessing”选项

问题描述 投票:0回答:1

python3.10/multiprocessing/spawn.py
 中以调试模式运行 
Pytest
 时,我看到在 
Pycharm

中执行以下代码的零星实例
def _check_not_importing_main():
    if getattr(process.current_process(), '_inheriting', False):
        raise RuntimeError('''
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.''')

我以前从未见过这个。

--multiprocessing
中运行
pytest
时,有什么方法可以禁用
pycharm
- 作为预期的解决方法吗?

正在生成的命令行是

venv/bin/python3 /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py 
  --multiprocess --qt-support=auto --client 127.0.0.1 --port 50192 --file ```

I am on `Pycharm 2022.3.1 Professional Edition`
python pycharm
1个回答
0
投票

启动附加线程的代码通常只能由主线程调用。 (也有例外。)。此代码应该位于

if __name__ == "__main__"
内部或从
if __name__ == "__main__"
内部调用的函数内部。

此消息警告您,您有一个正在启动新进程的顶级调用。这是一个错误。

© www.soinside.com 2019 - 2024. All rights reserved.