Script not terminating
Posted: Fri Mar 07, 2014 2:42 am
I'm trying to make a script that will manage some of the tasks I have to deal with daily. Right now I just want it to list all of the torrents and their labels.
I can't figure out how to get the script to exit when it is finished. It doesn't look like twisted is disconnecting the reactor.
I commented out some lines just for testing, but they don't seem to help.
I have also posted the question on stackoverflow, which got me a little further, but wasn't able to get that last piece working. Jean-Paul from stackoverflow suggested I use task.react(), but I couldn't find any valuable information on the method.
I can't figure out how to get the script to exit when it is finished. It doesn't look like twisted is disconnecting the reactor.
Code: Select all
class Deluge(object):
def __init__(self,*args):
for key, value in enumerate(args):
self.key = value
def getDownloadQueue(self):
self.connect("getQueue")
logging.debug("Finished getDownloadQueue()")
# self.disconnect()
def connect(self,params):
logging.debug("client.connect()")
deluge = client.connect()
logging.debug("deluge.addCallback()")
#deluge.addCallback(self.onConnect,params).addErrback(self.onConnectFail).addBoth(self.disconnect)
from twisted.internet import task
task.react(self.onConnect,[])
# reactor.run()
logging.debug("Finished connect()")
def disconnect(self):
client.disconnect()
# reactor.stop()
logging.debug("Finished disconnect()")
def onConnect(self,result):
params = "getQueue"
def onGetTorrentStatus(torrentInfo):
logging.debug("Starting onGetTorrentStatus()")
#print torrentInfo["name"] + " " + torrentInfo["label"]
# if torrent["name"] == torrent_name:
# print "File '%s' already exists" % torrent["name"]
# return
def onGetSessionState(torrent_ids):
print torrent_ids
logging.debug("Got all torrent ids")
for id in torrent_ids:
d = client.core.get_torrent_status(id, ["name","label"]).addCallback(onGetTorrentStatus)
print defer.gatherResults([d, self.disconnect])
if params == "getQueue":
client.core.get_session_state().addCallback(onGetSessionState)
logging.info("Finished onConnect")
def onConnectFail(self,result):
print "Error: %s" % result
# reactor.stop()
I have also posted the question on stackoverflow, which got me a little further, but wasn't able to get that last piece working. Jean-Paul from stackoverflow suggested I use task.react(), but I couldn't find any valuable information on the method.