from multiprocessing import Pool import subprocess import os import signal import sys import time def mp_logic(): return '' def main(): cnt=1 process_pool = Pool(processes=1, maxtasksperchild=1) while True: with subprocess.Popen(['ls', '/tmp'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p: # avoid hanging on big output buffers std_out, std_err = p.communicate() print('Done process', cnt, flush=True) cnt+= 1 res = process_pool.apply_async(mp_logic, args=()) time.sleep(0.1) x = res.get() if __name__ == "__main__": main()