我正在使用 mod_python 在 Apache 中运行 Trac。 我正在开发一个插件,不确定全局变量是如何存储/缓存的。
我是 python 新手,在 google 上搜索了该主题,发现 mod_python 缓存了 python 模块(我认为)。 但是,我希望在 Web 服务重新启动时重置缓存,但事实似乎并非如此。 我这样说是因为我有一个全局变量,它是一个列表,我测试该列表以查看值是否存在,如果不存在,则添加它。 我第一次运行此命令时,它向列表中添加了三个条目。 随后,该列表从一开始就有三个条目。
例如:
globalList = []
class globalTest:
def addToTheList(itemToAdd):
print(len(globalTest))
if itemToAdd not in globalList:
globalList.append(itemToAdd)
def doSomething():
addToTheList("I am new entry one")
addToTheList("I am new entry two")
addToTheList("I am new entry three")
上面的代码只是我正在做的事情的一个例子,而不是实际的代码;-)。 但本质上 doSomething() 方法是由 Trac 调用的。 第一次运行时,它添加了所有三个条目。 现在 - 即使重新启动 Web 服务器后,len(globalList) 命令也始终为 3。
我怀疑答案可能是我的会话(以及全局变量)正在被缓存,因为 Trac 正在记住我的登录信息Web 服务器重新启动后刷新 Trac 中的页面时的详细信息。 如果是这种情况 - 我该如何强制清除缓存。 请注意,我不想手动重置 globalList 变量,即 globalList.length = 0
任何人都可以提供有关正在发生的情况的任何见解吗?
谢谢
I'm using mod_python to run Trac in Apache. I'm developing a plugin and am not sure how global variables are stored/cached.
I am new to python and have googled the subject and found that mod_python caches python modules (I think). However, I would expect that cache to be reset when the web service is restarted, but it doesn't appear to be. I'm saying this becasue I have a global variable that is a list, I test the list to see if a value exists and if it doesn't then I add it. The first time I ran this, it added three entries to the list. Subsequently, the list has three entries from the start.
For example:
globalList = []
class globalTest:
def addToTheList(itemToAdd):
print(len(globalTest))
if itemToAdd not in globalList:
globalList.append(itemToAdd)
def doSomething():
addToTheList("I am new entry one")
addToTheList("I am new entry two")
addToTheList("I am new entry three")
The code above is just an example of what I'm doing, not the actual code ;-). But essentially the doSomething() method is called by Trac. The first time it ran, it added all three entries. Now - even after restarting the web server the len(globalList) command is always 3.
I suspect the answer may be that my session (and therefore the global variable) is being cached because Trac is remembering my login details when I refresh the page in Trac after the web server restart. If that's the case - how do I force the cache to be cleared. Note that I don't want to reset the globalList variable manually i.e. globalList.length = 0
Can anyone offer any insight as to what is happening?
Thank you
发布评论
评论(2)
阅读 mod-python 常见问题解答,它说
去链接
http://www.modpython.org/ FAQ/faqw.py?req=show&file=faq03.005.htp
所以问题是为什么要使用全局变量?
read the mod-python faq it says
go to link
http://www.modpython.org/FAQ/faqw.py?req=show&file=faq03.005.htp
so question is why you want to use global variable?
强制:
使用 wsgi rel="nofollow noreferrer">
mod_wsgi
。不要使用
mod_python
。可使用 trac 配置
mod_wsgi
帮助 。Obligatory:
Switch to wsgi using
mod_wsgi
.Don't use
mod_python
.There is Help available for configuring
mod_wsgi
with trac.