multiproc.py 830 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Job pools for multiprocessing.
  2. """
  3. from builtins import map
  4. from builtins import object
  5. import multiprocessing
  6. class FakePool(object):
  7. """Fake version of multiprocessing.Pool
  8. """
  9. def map(self, func, iterable, chunksize=None):
  10. return list(map(func, iterable))
  11. def imap(self, func, iterable, chunksize=None):
  12. return list(map(func, iterable))
  13. def terminate(self):
  14. pass
  15. def __init__(self, initializer=None, initargs=[], *args, **kwds):
  16. if initializer:
  17. initializer(*initargs)
  18. def Pool(processes, *args, **kwds):
  19. """Pool factory.
  20. If 'not processes', return our FakePool;
  21. otherwise, a multiprocessing.Pool.
  22. """
  23. if processes:
  24. return multiprocessing.Pool(processes, *args, **kwds)
  25. else:
  26. return FakePool(*args, **kwds)