2016-04-06 15 views
1

私のプロジェクトではpathos.multiprocessing.Poolを使用しようとしています。 しかし、プールを終了すると、次の問題が発生します。 CentOS 6.5を使用していますが、pathos.multiprocessing.Poolやその他の問題が原因であるかどうかはわかりません。いつかpathos.multiprocessing.Poolを正しく終了できません

Traceback (most recent call last): 
File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner 
    self.run() 
File "/usr/local/lib/python2.7/threading.py", line 1073, in run 
    self.function(*self.args, **self.kwargs) 
File "receiver.py", line 132, in kill_clients 
    pool.terminate() 
File "/usr/local/lib/python2.7/site-packages/multiprocess/pool.py", line 465, in terminate 
    self._terminate() 
File "/usr/local/lib/python2.7/site-packages/multiprocess/util.py", line 207, in __call__ 
    res = self._callback(*self._args, **self._kwargs) 
File "/usr/local/lib/python2.7/site-packages/multiprocess/pool.py", line 513, in _terminate_pool 
    p.terminate() 
File "/usr/local/lib/python2.7/site-packages/multiprocess/process.py", line 137, in terminate 
    self._popen.terminate() 
File "/usr/local/lib/python2.7/site-packages/multiprocess/forking.py", line 174, in terminate 
    os.kill(self.pid, signal.SIGTERM) 

OSErrorの:[errnoを3]いいえ、そのようなプロセス

有線事は冒頭で、それがうまく機能していることです。しかし、4番目の仕事が受け取られると、そのような問題があります。

class Receiver: 
    def __init__(self): 
     .... 
     self.results={} 
    def kill_clients(self, client_list, pool): 
     for client in client_list: 
      client.kill() 
     pool.terminate() 
    def process_result(self, result): 
     if result is None: 
      self.results = {} 
      return 
     res = result.split(':') 
     if len(res) != 4: 
      raise Exception("result with wrong format: %s" % result) 
     self.results['%s_%s' % (res[0], res[1])] = {"code": res[3], "msg": res[4]} 
    ... 

    def handler(self, job): 
     self.lg.debug("Receive job in rtmp_start_handler.") 
     self.lg.debug("<%s>" % str(job)) 
     # each client corresponding one process 
     cli_counts = job['count'] 
     pool = Pool(processes=cli_counts) 
     clients = [] 
     try: 
      for i in xrange(cli_counts): 
       rtmp_cli = RtmpClient(job['case'], i) 
       clients.append(rtmp_cli) 
      [pool.apply_async(client.run, callback=self.process_result) 
      for client in clients] 
      pool.close() 
      sleep(1) 
      self.lg.debug("All clients are started.") 
      t = Timer(
       job['timeout'], 
       self.kill_clients, 
       args=(clients, pool) 
      ) 
      t.start() 
      self.lg.debug("Timer is started. timeout %s s" % job['timeout']) 
      pool.join() 
     except Exception, e: 
      self.lg.warning("Exception occurred: %s" % e) 
      self.lg.warning(format_exc()) 
      return "0" 

     # here the self.results shall be ready 
     return self.parse_results() 

答えて

0

OSErrorは、プールによってではなく、プログラムの問題によって発生します。 Popenを使用してサブプロセスを作成し、exec ffmpegを実行するとすぐに終了します(他の問題のため)。サブプロセスを終了しようとすると、その時点では存在しません。そのため、OSErrorが発生します。

関連する問題