Python螺纹。条件()跨多个进程的功能

2024-05-19 19:17:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用mod\WSGI编写一个WSGI应用程序。我想拥有许多并发连接的能力。modüwsgi为每个请求启动一个新进程,使其无法使用螺纹。条件()用于通知从一个线程到另一个线程的更改。在

我知道有几种不同的方法可以在不同的运行进程(RPC、AMQP、d-bus、Jabber)之间提供实时消息传递,但我所寻找的是一种类似于一行程序的方法线程。等待()和线程.notifyAll(). 在

当我不使用mod_wsgi,只运行多个线程时,这里基本上就是我为我工作的东西。显然,这两个函数是由不同的线程运行的:

def put_value:
    # user has given a new value
    # update in DB, then notify any waiting threads

    my_condition.acquire()
    my_condition.notifyAll()
    my_condition.release()

def get_value:
    # user has requested to receive a new value as of this point
    # we will return a value as soon as we are notified it has changed

    my_condition.acquire()
    my_condition.wait()
    my_condition.release()
    # return some val out of the DB

再一次,我要找的是一个类似于单行线的东西线程。等待()和线程.notifyAll(). 我不介意设置一些配置,甚至在后台运行的东西——但是我有相当多的代码依赖于在请求中间停止并等待,直到通知它它可能继续。在


Tags: 方法modwsginew进程valuemydef