2024-05-19 08:59:38 发布
网友
我想启动一个Flask服务器,它是由SwaggerUI作为另一个Python脚本中的线程创建的。启动它的命令使用-m标志(python -m swagger_server)。如何在Python脚本中使用-m标志
-m
python -m swagger_server
我试着使用runpy模块
runpy
runpy.run_module('swagger_server')
但它只是执行并完成,什么也不做
大多数包只在__main__范围内运行,以防止在导入时运行
__main__
runpy.run_module()基于run_name参数设置__name__:
runpy.run_module()
run_name
__name__
__name__ is set to run_name if this optional argument is not None, to mod_name + '.__main__' if the named module is a package and to the mod_name argument otherwise. https://docs.python.org/3/library/runpy.html
None
mod_name + '.__main__'
mod_name
您可以通过将run_name设置为__main__来运行包:
runpy.run_module('swagger_server', run_name='__main__')
大多数包只在
__main__
范围内运行,以防止在导入时运行runpy.run_module()
基于run_name
参数设置__name__
:您可以通过将
run_name
设置为__main__
来运行包:相关问题 更多 >
编程相关推荐