# -*- coding: utf-8 -*- import time from multiprocessing import Pool def len2(x): time.sleep(10) return len(x) if __name__ == '__main__': p = Pool(processes=1) try: # You have 10 secs to type ^C to hang the interpreter assert sum(p.map(len2, ['ab', 'c'])) == 3 p.close() except: p.terminate() raise finally: p.join()