且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在wsgi应用程序中生成线程可以吗?

更新时间:2023-01-12 12:03:34

FWIW,还有一个阅读:

FWIW, also have a read of:

http://code.google.com/p/modwsgi/wiki/注册CleanupCode

在ActionScript中,只有在WSGI规范本身的上下文中执行延迟工作才是唯一的方法来关闭()iterable。虽然这不是在单独的线程中,并且将发生在实际请求的上下文中,尽管响应应该已被刷新回客户端。因此,您的延迟操作将消耗该请求线程,直到工作完成,因此请求线程在此之前无法处理其他请求。

The hooking of actions to close() of iterable is the only way within context of the WSGI specification itself for doing deferred work. That isn't in a separate thread though and would occur within the context of the actual request, albeit after the response is supposed to have been flushed back to the client. Thus your deferred action will consume that request thread until the work is complete and so that request thread would not be able to handle other requests until then.

一般来说,如果您使用后台线程,不能保证任何主机机制将等到这些后台线程在关闭进程之前完成。实际上,甚至不能想到任何标准的部署机制,等等。甚至没有真正的保证,在过程关闭时将会调用atexit处理程序,引用的文档也会简要介绍一下。

In general, if you do use background threads, there is no guarantee that any hosting mechanism would wait until those background threads complete before shutting process down. In fact, can't even think of any standard deployment mechanism which does wait. There isn't really even a guarantee that atexit handlers will be called on process shutdown, something that the referenced documentation also briefly talks about.