stream reads every 1s, even if nothing, so pop can occur regularly
parent
ee46eb9897
commit
5049d97a24
|
|
@ -27,15 +27,27 @@ def with_(N, R, T, p):
|
|||
|
||||
bucket = Bucket(N, R, T, cb.cb())
|
||||
|
||||
while readline():
|
||||
bucket.push()
|
||||
while True:
|
||||
got = readline()
|
||||
if got:
|
||||
bucket.push()
|
||||
else:
|
||||
bucket.pop()
|
||||
|
||||
def readline():
|
||||
try:
|
||||
line = input()
|
||||
return True
|
||||
except EOFError:
|
||||
return False
|
||||
def __input(*args):
|
||||
return input()
|
||||
def _input(*args):
|
||||
try:
|
||||
foo = __input()
|
||||
except Exception as e:
|
||||
foo = None
|
||||
return foo
|
||||
timeout = 1
|
||||
signal.signal(signal.SIGALRM, __input)
|
||||
signal.alarm(timeout)
|
||||
foo = _input()
|
||||
return not foo is None
|
||||
|
||||
class Bucket:
|
||||
def __init__(self, N, R, T, CB):
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ set -o pipefail
|
|||
cleanup() {
|
||||
kill -9 $(jobs -p) || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap cleanup EXIT
|
||||
|
||||
python3 ./state_to_buttons.py &
|
||||
|
||||
(
|
||||
while echo ""; do
|
||||
if [ 0 == $((RANDOM%4)) ]; then
|
||||
while echo ""; do
|
||||
if [ 0 == $((RANDOM%4)) ]; then
|
||||
sleep 3
|
||||
fi
|
||||
date >&2
|
||||
done
|
||||
) | python3 ./stream_to_state.py
|
||||
) | python3 ./stream_to_state.py
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue