stream reads every 1s, even if nothing, so pop can occur regularly

master
Bel LaPointe 2022-04-11 07:28:19 -06:00
parent ee46eb9897
commit 5049d97a24
2 changed files with 23 additions and 11 deletions

View File

@ -27,15 +27,27 @@ def with_(N, R, T, p):
bucket = Bucket(N, R, T, cb.cb()) bucket = Bucket(N, R, T, cb.cb())
while readline(): while True:
bucket.push() got = readline()
if got:
bucket.push()
else:
bucket.pop()
def readline(): def readline():
try: def __input(*args):
line = input() return input()
return True def _input(*args):
except EOFError: try:
return False 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: class Bucket:
def __init__(self, N, R, T, CB): def __init__(self, N, R, T, CB):

View File

@ -6,16 +6,16 @@ set -o pipefail
cleanup() { cleanup() {
kill -9 $(jobs -p) || true kill -9 $(jobs -p) || true
} }
trap cleanup EXIT trap cleanup EXIT
python3 ./state_to_buttons.py & python3 ./state_to_buttons.py &
( (
while echo ""; do while echo ""; do
if [ 0 == $((RANDOM%4)) ]; then if [ 0 == $((RANDOM%4)) ]; then
sleep 3 sleep 3
fi fi
date >&2 date >&2
done done
) | python3 ./stream_to_state.py ) | python3 ./stream_to_state.py