我可以使用Python在后台运行rtorrent客户机吗?我试图使用来自子进程导入Popen的管道导入线程来完成它。
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此脚本试图使用rTorrent运行线程,并在循环中键入PID。但是,当我将客户机作为stdin和stdout的/dev/null运行时,它不会运行。在此代码中,当我更改为:process = Popen(self.torrent.getRun(),stdout=PIPE,stdin=PIPE)时,当rtorrent关闭时,主线程正在等待。
也许有人会帮助解决这个问题,或者我做错了什么。
发布于 2011-06-27 17:31:32
这里有两个问题:
中运行它,则是无用的。
https://stackoverflow.com/questions/6496355
复制相似问题