2011-06-27 3 views
0

Pythonを使用してバックグラウンドでrtorrentクライアントを実行できますか?私はサブプロセス輸入popenのからPIPEインポートスレッドを使用してそれを実行しようとしています 、PIPEバックグラウンドでのrtorrentの使用Python

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が閉じている間、メインスレッドが待機しています。

誰かがこの問題の解決に役立つか、多分私は何か間違ったことをしています。ここ

答えて

0

2つの問題:

  1. process.communicate()プロセスが終了するまでブロックします。
  2. rtorrentは端末で実行するように設計されていますが、tty/ptyで実行しないと役に立たなくなります。
+0

ありがとうございました。私は間違いを理解しています。いいえ、rtorrent使用画面を実行し、ロックファイルからPIDを取得しないでください。 – Evgeniy

関連する問題