Created
November 16, 2013 21:11
-
-
Save zed/7505372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Make zombies using `.wait()`. | |
http://stackoverflow.com/questions/2760652 | |
""" | |
import os | |
from threading import Timer | |
from subprocess import Popen | |
n = 10 | |
many_seconds = 10 | |
def check_zombies(expected_nzombies): | |
#NOTE: don't use Popen() here | |
output = os.popen(r"ps aux | grep Z | grep -v grep").read() | |
print(output) | |
got_nzombies = len(output.splitlines()) - 1 | |
assert expected_nzombies == got_nzombies | |
check_zombies(0) # no zombies | |
processes = [Popen("sleep %d" % many_seconds, shell=True)] | |
processes.extend(Popen("sleep 1", shell=True) for _ in range(n)) | |
Timer(2, check_zombies, [n]).start() # should see zombies in 2 seconds | |
for p in processes: | |
p.wait() | |
check_zombies(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment