import subprocess, threading, time, gc, os def spawn(event) : subprocess.check_output("true") event.set() event = threading.Event() i = 0 next_msg = time.monotonic() + 1.0 while True : if next_msg <= time.monotonic(): print(i, "thread+subprocess", flush=True) os.system("grep VmRSS /proc/%s/status" % os.getpid()) next_msg = time.monotonic() + 1.0 event.clear() t = threading.Thread(target=spawn, args=(event,)) t.start() event.wait() t.join() i += 1 #gc.collect()