OILS / demo / cpython / signals.sh View on Github | oilshell.org

30 lines, 12 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# demo/cpython-signals.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -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
15print-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
21write-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?
26read-stdin() {
27 python -c 'import sys; sys.stdin.read()'
28}
29
30"$@"