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

wz1wpwve  于 2023-10-20  发布在  PyCharm
关注(0)|答案(1)|浏览(286)

当在Pycharm中以调试模式运行Pytest时,我看到以下代码在python3.10/multiprocessing/spawn.py中执行的零星示例

  1. def _check_not_importing_main():
  2. if getattr(process.current_process(), '_inheriting', False):
  3. raise RuntimeError('''
  4. An attempt has been made to start a new process before the
  5. current process has finished its bootstrapping phase.
  6. This probably means that you are not using fork to start your
  7. child processes and you have forgotten to use the proper idiom
  8. in the main module:
  9. if __name__ == '__main__':
  10. freeze_support()
  11. ...
  12. The "freeze_support()" line can be omitted if the program
  13. is not going to be frozen to produce an executable.''')

我以前从没见过这个。
pycharm中运行pytest时,是否有任何方法可以禁用--multiprocess-作为预期的解决方案?
正在生成的命令行为

  1. venv/bin/python3 /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py
  2. --multiprocess --qt-support=auto --client 127.0.0.1 --port 50192 --file ```
  3. I am on `Pycharm 2022.3.1 Professional Edition`
hl0ma9xz

hl0ma9xz1#

通常,启动附加线程的代码应该只由主线程调用。(也有例外)。这段代码应该在if __name__ == "__main__"内部,或者在从if __name__ == "__main__"内部调用的函数内部。
此消息警告您有一个正在启动新进程的顶级调用。这是个错误。

相关问题