Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
跨多个进程的Python threading.Condition()功能_Python_Multithreading - Fatal编程技术网

跨多个进程的Python threading.Condition()功能

跨多个进程的Python threading.Condition()功能,python,multithreading,Python,Multithreading,我正在使用mod_WSGI编写一个WSGI应用程序。我想拥有多个并发连接的能力。mod_wsgi为每个请求启动一个新进程,使得无法使用threading.Condition()通知从一个线程到另一个线程的更改 我知道有几种不同的方法可以在不同的运行进程之间提供实时消息传递(RPC、AMQP、d-bus、Jabber),但我特别想要的是类似于一行程序threading.wait()和threading.notifyAll()的方法 当我没有使用mod_wsgi,只是运行多个线程时,这里基本上就是我

我正在使用mod_WSGI编写一个WSGI应用程序。我想拥有多个并发连接的能力。mod_wsgi为每个请求启动一个新进程,使得无法使用threading.Condition()通知从一个线程到另一个线程的更改

我知道有几种不同的方法可以在不同的运行进程之间提供实时消息传递(RPC、AMQP、d-bus、Jabber),但我特别想要的是类似于一行程序threading.wait()和threading.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

再一次,我要寻找的是类似于一行程序threading.wait()和threading.notifyAll()的东西。我不介意设置一些配置,甚至在后台运行的东西——但是我有相当数量的代码依赖于在请求中间停止和等待直到被通知它可以继续。有关详细信息,请参阅。

mod_wsgi模块不会为每个请求启动新的进程。然而,mod_wsgi的某些配置是多进程的,所以请求可能不会每次都进入同一个进程。如果使用mod_wsgi的守护进程模式,默认为单进程,则不会出现此问题。我确实看到了这一点,问题是我不想在我们增长的情况下将自己限制在一台机器上的一个进程。这绝对是一个解决方案,它不能完全满足我的要求。