在GAE/Python中一次性放置每次代码的最佳位置在哪里? [英] Where is the best place to put one-time and every-time code in GAE/Python?

查看:76
本文介绍了在GAE/Python中一次性放置每次代码的最佳位置在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google App Engine和Python的新手.我无法理解有关在Google App Engine上运行的Python应用程序的一些基本问题.

I am new to Google App Engine and Python. I am having trouble understanding some basic questions about Python apps running on Google App Engine.

如果我想执行代码:

  1. 在每个传入请求上,我都应该放在哪里?我们正在捕获有关会话信息的信息,这些会话信息是关于何时由谁查看哪些页面以及它们执行了什么操作等.
  2. 启动应用后,只有一次,我应该放在哪里?我需要初始化许多在应用程序中许多地方使用的应用程序/系统变量.放置代码的最佳位置在哪里?

如果任何人都可以指出我的任何文档或教程来解释什么是GAE/Python应用程序的最佳体系结构实践,而又没有编程方面的基础知识,那就太好了.

If anyone can point me to any documentation or tutorials that explain what the best architecture practices are for GAE/Python apps, without the basics of programming stuff, that would be great.

推荐答案

问题编号1:

某些Web框架(Django,KAY等)具有中间件的概念.您可以创建自己的中间件,该中间件将在每个请求上执行并处理此类信息 (请参阅: https://docs.djangoproject.com/en/dev/topic/http/middleware/)

Question Number 1:

Some web frameworks (Django, KAY, etc) have a concept of Middleware. You can create your own middleware that will execute on every request and handle this sort of information (see: https://docs.djangoproject.com/en/dev/topics/http/middleware/)

预热请求(请参阅: https://developers.google. com/appengine/docs/python/config/appconfig#Warmup_Requests )

尽管由于不能保证预热请求能够运行,所以您可以放置​​一个全局变量来让实例知道实例是否已被初始化".并在每次页面加载时检查该变量(这将很便宜,因为该变量将存在于内存中并且存在于请求之间).如果未设置,则执行您的热身"操作.根据需要.

Though since warmup requests are not guaranteed to run, you can put a global variable to let the instance know if it was "initialized" and check that variable on every page load (this will be cheap since the variable will live in memory and exist between requests). If it is not set, then run through your "warmup" as needed.

这篇关于在GAE/Python中一次性放置每次代码的最佳位置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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