Last active
July 8, 2019 05:24
-
-
Save shenfeng/f4a24778227df77687bb 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
def fork_and_wait(args, s): | |
p = subprocess.Popen(args, stdout=subprocess.PIPE) | |
def wait(): | |
time.sleep(s) | |
if p.returncode is None: | |
logging.info("kill process %s", p.pid) | |
p.kill() | |
sys.exit(1) | |
elif p.returncode != 0: | |
logging.info("process return %d", p.returncode) | |
sys.exit(p.returncode) | |
t = threading.Thread(target=wait) | |
t.setDaemon(True) | |
t.start() | |
p.wait() | |
print p.stdout.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment