如果使用lighttpd驱动基于Django的web应用程序,每个调用是否都会创建一个新的Python解释器实例?

I'd like to be able to share some object instances between requests for managing asynchronous event delivery, but this seems like something that won't work with an event based server like lighttpd. Is that the case? What's the best way to work around this if that is the case?

Of note: This is not a standard web deployment. I'm trying to make this run on an embedded platform for local network only. So some typical deployment/scaling concerns are not really at play here and resources are at a premium.

#0

FastCGI is already long-running, so getting access to a long-lived object should just be a matter of assigning the object to a module-level variable somewhere.

# yourapp/async_thingy.py
_long_lived_object = None
def get_long_lived_object():
    global _long_lived_object
    if _long_lived_object is None:
        _long_lived_object = create_the_long_lived_object()
    return _long_lived_object

# views
from .async_thingy import get_long_lived_object
def the_view(request):
    # do whatever
    long_lived_obj = get_long_lived_object()
    long_lived_obj.whatever()
    # the rest of the view - return your response, etc.

I'd start with something like this. There are other potential issues if you're using multiple Python processes, but given your resource constraints I'm assuming that's not the case.

推荐文章

JS:根据每个子数组的长度对多维数组进行排序

JS:根据每个子数组的长度对多维数组进行排序

推荐文章

静态变量何时初始化?

静态变量何时初始化?

推荐文章

如何通过图形API编辑打开的图形对象的facebook页面?

如何通过图形API编辑打开的图形对象的facebook页面?

推荐文章

PHP-OOP:使用Construct创建新记录

PHP-OOP:使用Construct创建新记录

推荐文章

处理来自不同页面的ajax url?

处理来自不同页面的ajax url?

推荐文章

以编程方式切换片段

以编程方式切换片段

推荐文章

同步来自不同数据库的两个SQLITE表iphone ios

同步来自不同数据库的两个SQLITE表iphone ios

推荐文章

Android在ListView中实现聊天泡泡

Android在ListView中实现聊天泡泡

推荐文章

将调试语句重定向到stderr时出现奇怪的情况

将调试语句重定向到stderr时出现奇怪的情况

推荐文章

删除url的搜索部分

删除url的搜索部分

推荐文章

在javascript中使用html有麻烦吗?

在javascript中使用html有麻烦吗?

推荐文章

CakePHP消除分页中的空结果

CakePHP消除分页中的空结果

推荐文章

如何在继承自抽象用户控件的控件中设置依赖属性?

如何在继承自抽象用户控件的控件中设置依赖属性?

推荐文章

使用索引(i)在for循环中声明变量

使用索引(i)在for循环中声明变量

推荐文章

果园asp.netcms公司。它是开源的吗?

果园asp.netcms公司。它是开源的吗?