当在Pycharm
中以调试模式运行Pytest
时,我看到以下代码在python3.10/multiprocessing/spawn.py
中执行的零星示例
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.''')
我以前从没见过这个。
在pycharm
中运行pytest
时,是否有任何方法可以禁用--multiprocess
-作为预期的解决方案?
正在生成的命令行为
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`
1条答案
按热度按时间hl0ma9xz1#
通常,启动附加线程的代码应该只由主线程调用。(也有例外)。这段代码应该在
if __name__ == "__main__"
内部,或者在从if __name__ == "__main__"
内部调用的函数内部。此消息警告您有一个正在启动新进程的顶级调用。这是个错误。