Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 requestloop(loopCondition)不';即使loopCondition为False,也不能释放_Python_Pyro - Fatal编程技术网

Python requestloop(loopCondition)不';即使loopCondition为False,也不能释放

Python requestloop(loopCondition)不';即使loopCondition为False,也不能释放,python,pyro,Python,Pyro,我对Pyro4.Daemon对象的requestLoop方法有一些问题 我想要的是远程调用一个“stop()”方法来释放requestLoop函数并关闭我的守护进程 这个小例子不起作用 服务器 #!/usr/bin/python # -*- coding: utf-8 -*- from daemon import Pyro4 class Audit(object): def start_audit(self): with Pyro4.Daemon() as daemon

我对Pyro4.Daemon对象的requestLoop方法有一些问题

我想要的是远程调用一个“stop()”方法来释放requestLoop函数并关闭我的守护进程

这个小例子不起作用

服务器

#!/usr/bin/python
# -*- coding: utf-8 -*-
from daemon import Pyro4

class Audit(object):
    def start_audit(self):
        with Pyro4.Daemon() as daemon:
            self_uri = daemon.register(self)
            ns = Pyro4.locateNS()
            ns.register("Audit", self_uri)
            self.running = True
            print("starting")
            daemon.requestLoop(loopCondition=self.still_running)
            print("stopped")
            self.running = None

    def hi(self, string):
        print string

    def stop(self):
        self.running = False

    def still_running(self):
        return self.running

def main():

    # lancement de l'auditor
    auditor = Audit()
    auditor.start_audit()

if __name__ == "__main__" :
    main()
客户

import Pyro4

def main():

    with  Pyro4.Proxy("PYRONAME:Audit") as au:
        au.hi("hello")
        au.hi("another hi")
        au.stop()
我希望看到服务器打印“hello”和“Other hi”,然后关闭

但是关闭没有发生,服务器仍然在requestloop方法中被阻塞。 我想用多久就用多久

但是,如果我在第一次远程调用时创建另一个客户端,服务器将关闭,客户端将抛出一个错误:

Pyro4.errors.ConnectionClosedError: receiving: not enough data
我所有的测试都是说我需要创建第二个代理,并在我的服务器上抛出exeption来传递requestloop


有人知道如何解决这个问题吗?

如果您查看源代码中的
示例/callback/client.py
,您会看到以下评论:

# We need to set either a socket communication timeout,
# or use the select based server. Otherwise the daemon requestLoop
# will block indefinitely and is never able to evaluate the loopCondition.
Pyro4.config.COMMTIMEOUT=0.5
因此,您需要做的是在服务器文件中设置
COMMTIMEOUT
,根据我的测试,它可以正常工作


注意:您还可以将
print
语句添加到
still\u running
方法中,以检查何时调用它。如果没有上面的配置,您将看到该方法似乎仅在接收到新事件时才执行,因此服务器不会在接收到将
running
设置为
False
的下一个事件后关闭。例如,如果您执行客户端程序两次,服务器将关闭。

工作正常。非常感谢你。我读过一些关于超时的文档,上面说requestloop的超时时间为3秒。可能是旧版本?请注意,0.5秒的超时时间非常短。il使用此值尝试了一些超时异常:)3.5秒很好