How do I run custom python script in Google App engine

柔情痞子 提交于 2019-12-02 02:55:55

App Engine is PaaS product, not an IaaS one (on which you could, indeed, just run a linux image and install the cron you mentioned). You cannot run arbitrary standalone python scrips in GAE. You might be able to achieve what you want by re-working the script to meet the GAE apps requirements - basically make the functionality callable from inside a HTTP(S) handler.

For the 1st generation standard environment (python27 runtime):

  • the requirements.txt file isn't used by GAE. As you discovered, you can use it to vendor in your python dependencies, but there's more to do, see Copying a third-party library.
  • your script functionality needs to be re-worked as a WSGI app, which is what you configure in your app.yaml. From Handlers element:

A script: directive must be a python import path, for example, package.module.app that points to a WSGI application. The last component of a script: directive using a Python module path is the name of a global variable in the module: that variable must be a WSGI app, and is usually called ** ** by convention.

Note: just like for a Python import statement, each subdirectory that is a package must contain a file named init.py.

For the 2nd generation standard environment (python37 runtime):

  • dependencies are automatically installed from your requirements.txt file, see Specifying Dependencies
  • only auto can be specified in a script: statement in app.yaml, because the app itself is specified via the entrypoint: config. So you need need to rework your script to be invoked as handler in that app. From Runtime and app elements:

For your app to receive HTTP requests, entrypoint should contain a command which starts a web server that listens on the port specified by the PORT environment variable.

The flexible environment (with similar re-work as for the 2nd gen standard one) could be a better fit, especially because you can configure instances with more ram/cpu resources (which you might need judging by your requirements.txt file) than in the standard environment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!