使用Python在后台运行rtorrent

使用Python在后台运行rtorrent,python,background,daemon,Python,Background,Daemon,我可以在后台使用Python运行rtorrent客户端吗? 我正在尝试使用子流程import Popen,PIPE中的PIPE import线程来实现这一点 class RunClient(threading.Thread): queue_cmd = None torrent = None def __init__(self,q_cmd,torrent): self.queue_cmd = q_cmd threading.Thread._

我可以在后台使用Python运行rtorrent客户端吗? 我正在尝试使用子流程import Popen,PIPE中的PIPE import线程来实现这一点

class RunClient(threading.Thread):
    queue_cmd = None 
    torrent = None
    def __init__(self,q_cmd,torrent):
        self.queue_cmd = q_cmd
        threading.Thread.__init__(self)
        self.torrent = torrent

    def run(self):
        """Run client"""
        FNULL = open('/dev/null', 'w')
        print(self.torrent.getRun())
        process = Popen(self.torrent.getRun(),stdout=FNULL,stdin=FNULL)
        self.queue_cmd.put(process)
        process.communicate()[0]
此脚本应运行rTorrent并返回一个带有PID的对象

class Clients(threading.Thread):


    pids = {}
    q_cmd = None

    def __init__(self,q_cmd):
        """ """
        self.q_cmd = q_cmd
        threading.Thread.__init__(self)

    def startClient(self,id):
        """ """
        q = Queue.Queue(0)
        rClient = RunClient(q,Torrent())
        rClient.start()
        self.pids[id] = q.get()
        print self.pids

    def run(self):
        """Run torrent client"""
        print("Start thread...")
        self.startClient(50)
        i=0
        print("Start while...")
        while i<20:
            time.sleep(1)
            print(">>>",self.pids[50].pid)
            i=i+1
类客户端(threading.Thread):
pids={}
q_cmd=无
定义初始化(self,q_cmd):
""" """
self.q_cmd=q_cmd
threading.Thread.\uuuuu init\uuuuuu(自)
def startClient(自我,id):
""" """
q=队列。队列(0)
rClient=RunClient(q,Torrent())
rClient.start()
self.pids[id]=q.get()
打印self.pids
def运行(自):
“”“运行torrent客户端”“”
打印(“开始线程…”)
自启动客户端(50)
i=0
打印(“开始时…”)
而我这里有两个问题:

  • process.communicate()将一直阻止,直到进程终止
  • rtorrent设计为在终端中运行,如果您不在tty/pty中运行它,它是无用的

  • 谢谢。我理解我的错误。没有wI运行RTORENT use screen并从锁文件中获取PID。使用Python编写的Flouge不是更容易吗?