Author Cezary.Wagner
Recipients Cezary.Wagner
Date 2015-02-24.13:27:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424784474.12.0.228863603483.issue23510@psf.upfronthosting.co.za>
In-reply-to
Content
'with' code with manager will not work:
AttributeError: 'SyncManager' object has no attribute 'shutdown'

Test code:
# coding=utf-8
import multiprocessing
import multiprocessing.managers
import logging

def callback(result):
  print multiprocessing.current_process().name, 'callback', result

def worker(io_lock, value):
  # error
  raise RuntimeError()
  result = value + 1
  with io_lock:
    print multiprocessing.current_process().name, value, result
  return result

def main():
  manager = multiprocessing.managers.SyncManager()
  with manager:
    io_lock = manager.Lock()
    pool = multiprocessing.Pool(multiprocessing.cpu_count())
    for i in range(10):
      print pool.apply_async(worker, args=(io_lock, i), callback = callback)
    pool.close()
    pool.join()

if __name__ == '__main__':
  logging.basicConfig(level = logging.DEBUG)
  main()



See this code from multiprocessing.managers.SyncManager:

class SyncManager(BaseManager):
  pass

And now see 'with' methods in Basemanager:

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.shutdown()
History
Date User Action Args
2015-02-24 13:27:54Cezary.Wagnersetrecipients: + Cezary.Wagner
2015-02-24 13:27:54Cezary.Wagnersetmessageid: <1424784474.12.0.228863603483.issue23510@psf.upfronthosting.co.za>
2015-02-24 13:27:54Cezary.Wagnerlinkissue23510 messages
2015-02-24 13:27:53Cezary.Wagnercreate