这是一个来自dev.deluge-torrent.org的简单示例脚本,用于与 Deluge API 交互。
在 reactor.run() 之后没有任何反应,而且我没有收到“连接成功”消息,它只是永远挂起。
我在我的 Ubuntu 机器上运行它,它运行良好,但我无法让它在我真正想使用它的 Windows 机器上运行。
from deluge.ui.client import client
# Import the reactor module from Twisted - this is for our mainloop
from twisted.internet import reactor
# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()
# Connect to a daemon running on the localhost
# We get a Deferred object from this method and we use this to know if and when
# the connection succeeded or failed.
d = client.connect()
# We create a callback function to be called upon a successful connection
def on_connect_success(result):
print "Connection was successful!"
print "result:", result
# Disconnect from the daemon once we successfully connect
client.disconnect()
# Stop the twisted main loop and exit
reactor.stop()
# 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 "Connection failed!"
print "result:", result
# We add the callback (in this case it's an errback, for error)
d.addErrback(on_connect_fail)
# Run the twisted main loop to make everything go
reactor.run()
我不知道如何调试这个问题。我对 Twisted 很陌生,据我了解,这是一个巨大的图书馆。