-
-
Save zed/a16c3321ec8e5fbb8066 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 | |
"""Demonstrate that Ctrl-C (twice) interrupts a Python script with subprocess.""" | |
import sys | |
from subprocess import Popen, PIPE | |
p = Popen([sys.executable or "python", "-uc", """ | |
import time | |
n = int(input()) | |
for i in range(n): | |
print("{:0{}d}".format(i, len(str(n)))) | |
time.sleep(1) | |
"""], stdin=PIPE) | |
try: | |
p.communicate("300") | |
except KeyboardInterrupt: | |
print("got sigint") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment