在服务器上运行脚本,在Python应用程序引擎中启动 [英] Running script on server start in google app engine, in Python

查看:116
本文介绍了在服务器上运行脚本,在Python应用程序引擎中启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次dev服务器启动时是否可以运行脚本?还有在每次部署到谷歌?

Is it possible to run a script each time the dev server starts? Also at each deploy to google?

我希望应用程序根据某些方法返回的内容填充数据库。

I want the application to fill the database based on what some methods returns.

有没有办法做到这一点?

Is there any way to do this?

.. fredrik

..fredrik

推荐答案

我用django助手使用appengine python。据我所知,你不能在部署上挂钩任何东西,但你可以打一个电话来检查你是否需要在main.py的main函数中进行设置。这就是助手如何在第一次请求时初始化自己。我在一段时间没有看过webapp,但我认为main.py的行为与该框架类似。

I use appengine python with the django helper. As far as I know you cannot hook anything on the deploy, but you could put a call to check if you need to do your setup in the main function of main.py. This is how the helper initializes itself on the first request. I haven't looked at webapp in a while, but I assume main.py acts in a similar fashion for that framework.

请注意,main运行在第一个请求,而不是首次部署时。如果appengine启动一个新实例来处理负载,或者如果所有实例都由于不活动而停止,它也会发生。因此,请确保您检查是否需要进行初始化,然后只在需要时执行。

Be aware that main is run on the first request, not when you first deploy. It will also happen if appengine starts up a new instance to handle load, or if all instances were stopped because of inactivity. So make sure you check to see if you need to do your initialization and then only do it if needed.

这篇关于在服务器上运行脚本,在Python应用程序引擎中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆