""" Using Python 3.6.0 (python3.6 test.py): Traceback (most recent call last): File "/usr/local/lib/python3.6/multiprocessing/queues.py", line 241, in _feed obj = _ForkingPickler.dumps(obj) File "/usr/local/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps cls(buf, protocol).dump(obj) TypeError: can't pickle _thread.RLock objects --------------- No issues in Python 3.5.x """ import concurrent.futures import sys import time class Processor(): def __init__(self): self._futures = set() def _consume(self, d): print(d) def start(self): while 1: try: with concurrent.futures.ProcessPoolExecutor( max_workers=8) as executor: while 1: for n in range(10): future = executor.submit(self._consume, n) self._futures.add(future) time.sleep(5) except concurrent.futures.process.BrokenProcessPool: for f in self._futures: f.cancel() executor.shutdown() except KeyboardInterrupt: for f in self._futures: f.cancel() sys.exit(0) time.sleep(5) def main(): processor = Processor() processor.start() if __name__ == '__main__': main()