2

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

    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

但不是预期的下载速率。

感谢您的时间。

此致。

4

2 回答 2

3

这对我使用reactor.crash()for loop, reactor.start()do something, stop and repeat 有用。. .

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)
于 2015-06-03T09:26:37.747 回答
1

反应堆不可重新启动。你打reactor.run()一次。您可以在反应器运行时建立任意数量的连接。reactor.stop()当您准备好退出程序时调用。

另请参阅使用扭曲连接两次 - 如何正确执行此操作?

于 2013-10-22T21:57:15.513 回答