我正在构建一个Flask web应用程序,并希望在应用程序启动时运行一些后台服务。
例如,在网络应用程序中,您可以添加服务帐户、路由器ip、服务器ip等。我想让一些后台服务运行网络扫描、wmi调用和其他一些任务,以不断更新数据库中的相关信息。
在Rails中,我在config/initializers
中使用了初始化程序来启动一些守护进程:
# Start all the daemons to update the DB
system('script/daemon restart vs_updater.rb')
system('script/daemon restart c_fw_updater.rb')
system('script/daemon restart sans_updater.rb')
system('script/daemon restart sf_updater.rb')
Flask有这样的等价物吗?还是应该构建单独的脚本并以不同的方式运行它们?
您可以将命令添加到根目录中的__init__.py
文件中,并使用子进程运行脚本
from subprocess import call
call("script/daemon restart vs_updater.py")
晶圆厂http://www.fabfile.org/
子流程https://docs.python.org/2/library/subprocess.html