python - 如何重启twisted和deluge客户端rpc的reactor

标签 python twisted

我在使用扭曲框架时遇到问题,无法重新启动。 我的代码需要连接到一些不同节点中的不同 deluged 客户端守护进程。为此,我需要先断开连接,但扭曲不允许我重新连接到另一个客户端。 这是我的代码:

    ip = ['localhost', 'debci-lab']
    for i in range(len(ip)):
    ip_connect = ip[i]
    d = client.connect(host=ip_connect)
    # We create a callback function to be called upon a successful connection
    def on_get_config(result):
    print result

    def on_connect_success(result):
        print "Connection was successful!"
        print "result:", result
        client.core.get_torrent_status('dd69058c737d914c4e8e985d47a29606de80d34e', ['download_payload_rate']).addCallback(on_get_config)
        client.disconnect()
    # We add the callback to the Deferred object we got from connect()
    d.addCallback(on_connect_success)

    # We create another callback function to be called when an error is encountered
    def on_connect_fail(result):
        print "result:", result

    # We add the callback (in this case it's an errback, for error)
    d.addErrback(on_connect_fail)

    reactor.run()

该循环仅运行一次,并输出: 连接成功! 结果:10

但不是预期的 download_rate。

感谢您的宝贵时间。

致以诚挚的问候。

最佳答案

这对我有用,使用 reactor.crash() for 循环,reactor.start() 做一些事情,停止并重复。 。 .

def main(myrequest):
    print myrequest
    data=[]
    errors=[]

    def got_data(mydata):
        data.append(mydata)
        process()

    def no_data(err):
        print >>sys.stderr, 'failed:', err
        errors.append(err)
        process()

    def process():
        if errors or data:
            reactor.crash()

    make_request("localhost", 9000, got_data, no_data, myrequest)

    return data

if __name__ == '__main__':
    bbg=["DBK GY EQUITY","IBM US Equity"]
    flds=["DVD_HIST"]
    for b in bbg:
        myrequest=bulk(b , flds)
        print ">>>>>>>>>>>>>>", main(myrequest)

关于python - 如何重启twisted和deluge客户端rpc的reactor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19528418/

相关文章:

javascript - 使用 javascript 将 Web 表单值传递给 python 脚本

python - python 中的 (**) 和 (<<) 有什么区别?

python - FFT - 峰峰值、峰值、RMS

php - 用 erlang 实现 Comet 并将其用于 PHP 应用程序

multithreading - Twisted:同时使用多个线程和进程

用于网络的 Python 线程 - 线程不并行运行

python - 被一行Python难住了

python - numpy 的 bincount 函数的反函数

python - 使用 python 和 twisted 通过 telnet 的 Http

twisted - 服务之间如何通信?