bpython / curtsies

Curses-like terminal wrapper with a display based on compositing 2d arrays of text.
MIT License
228 stars 52 forks source link

SigInt events get buffered until another key is pressed #165

Closed thomasballinger closed 3 years ago

thomasballinger commented 3 years ago
import curtsies
import sys
input_generator = curtsies.input.Input(
    keynames="curtsies", sigint_event=True, paste_threshold=None
)

with input_generator as g:
    for x in g:
        print(x)

pressing a, ctrl-c, b, ctrl-c, c, ctrl-d produces

tomb (master) curtsies$ python test.py
a
b
<SigInt Event>
c
<SigInt Event>

so these sigints are waiting for the next key event.

thomasballinger commented 3 years ago

Nevermind, this was just me not understanding how this script worked.

thomasballinger commented 3 years ago

Reopened, added Cbreak() and it's still there.

thomasballinger commented 3 years ago

I bet this is it:

Changed in version 3.5: The function is now retried with a recomputed timeout when interrupted by a signal, except if the signal handler raises an exception (see PEP 475 for the rationale), instead of raising InterruptedError. https://docs.python.org/3/library/select.html#select.select

https://www.python.org/dev/peps/pep-0475/ describes the change.

Yep! Fixed by https://github.com/bpython/curtsies/pull/166

thomasballinger commented 3 years ago

This is a big behavior change (back to how it is documented + used to work)! It seems just better, so I'm ok with possibly breaking consumers.