首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在后台运行rtorrent使用Python

在后台运行rtorrent使用Python
EN

Stack Overflow用户
提问于 2011-06-27 17:06:11
回答 1查看 996关注 0票数 0

我可以使用Python在后台运行rtorrent客户机吗?我试图使用来自子进程导入Popen的管道导入线程来完成它。

代码语言:javascript
复制
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的对象。

代码语言:javascript
复制
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关闭时,主线程正在等待。

也许有人会帮助解决这个问题,或者我做错了什么。

EN

回答 1

Stack Overflow用户

发布于 2011-06-27 17:31:32

这里有两个问题:

  1. process.communicate()将被阻塞,直到进程被设计为在终端中运行,如果没有在tty/pty.

中运行它,则是无用的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6496355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档