| 1 | #!/usr/bin/env bash
 | 
| 2 | #
 | 
| 3 | # Usage:
 | 
| 4 | #   demo/cpython-signals.sh <function name>
 | 
| 5 | 
 | 
| 6 | set -o nounset
 | 
| 7 | set -o pipefail
 | 
| 8 | set -o errexit
 | 
| 9 | 
 | 
| 10 | # I get EPIPE, but I don't get KeyboardInterrupt.
 | 
| 11 | # Which calls can raise KeyboardInterrupt?
 | 
| 12 | 
 | 
| 13 | # https://stackoverflow.com/questions/35571440/when-is-keyboardinterrupt-raised-in-python
 | 
| 14 | 
 | 
| 15 | print-pipe() {
 | 
| 16 |   # This should fill up a pipe.
 | 
| 17 |   # Can't seem to get KeyboardInterrupt
 | 
| 18 |   python -c 'print "x"*100000' | sleep 1
 | 
| 19 | }
 | 
| 20 | 
 | 
| 21 | write-pipe() {
 | 
| 22 |   python -c 'import sys; sys.stdout.write("x"*100000)' | sleep 1
 | 
| 23 | }
 | 
| 24 | 
 | 
| 25 | # The easiest way to see KeyboardInterrupt.  read and write are not symmetric?
 | 
| 26 | read-stdin() {
 | 
| 27 |   python -c 'import sys; sys.stdin.read()'
 | 
| 28 | }
 | 
| 29 | 
 | 
| 30 | "$@"
 |