It's all fun and games until someone [XOFF]
rachelbythebay.com
rachelbythebay.com
Apparently this is a fairly common problem. Take a look at: https://raam.org/2007/recovering-from-ctrls-in-putty/ The scrollbar should give some indication of how many "Thank You's" this article warranted!
I imagine your broken code did something like:
#XXX WRONG, DON'T DO IT
p = Popen(cmd, stdout=PIPE)
p.wait() #XXX deadlock is possible if cmd generates enough output
output = p.stdout.read()
To avoid the deadlock, it is enough to swap the last two statements: p = Popen(cmd, stdout=PIPE)
output = p.stdout.read()
p.wait()
that you would normally write as: output = check_output(cmd) # 2.7+
If you need to consume more than one pipe separately then you should consume them concurrently and therefore you need threads or async.io.`Popen.communicate()` can read from both pipes concurrently (as you've mentioned) and it is always available. It was available even in Python 2.4 that introduced the subprocess module.
"But the docs say that C-r searches backwards through history and C-s is forward"...test....um.
I've always attributed these hangs to the sad fact that hitting ^A can fairly easily come off as "^A ^S", especially when you do the keyboard hit with a slightly rolling hand motion. And as that key combination means "send ^S to the process inside screen", it results the inner process receiving SIGSTOP. Of course, the recovery is nearly the same as in the article: ^A ^Q.
For a screen user both have the same cargo-cult solution - just send enough SIGCONTs to the screen to get the application responding again.
I suspect that tmux chose ^B as the default command key to prevent accidental process hangs.
SIGSTOP is like SIGTSTP, the signal usually generated by ^Z, except (like SIGKILL, signal number 9) it's not possible to catch it. It makes the process stop doing anything at all until something sends SIGCONT (which shows up in ps output as state T).
Also of note, besides "TSTOP/TSTART" (^S/^Q) - as I knew it before XOFF/XON became the standard nomenclature courtesy of ASCII (X = Transmission), is of course the good ol' ^L, which is affectionately known as the boss-key in some parts. Life can't persist without some ^M and ^N business as well, and lets never forget the favourite "wake up your co-worker and go get coffee", ^G, although for some this may require your terminal have a buzzer or other suitable charge-based co-worker wake-up circuitry.
Well, I'm sure there are more in the alphabet to discover, but I'll just leave you here with the reminder that ^C and a few others of the happy little family of ^W control sequences are really but a few bytes away. ^Z
^D
stty -ixon
In your .profile/shrc for your shell of choice. I've never needed flow control and never probably will, this stops that junk.It occurs to me that I grew up on the BBC Micro, where pressing Ctrl+Shift would pausing scrolling, so being able to do this is tightly engrained in muscle memory...
Only time i've ever used it was when booting a system to stop output on a serial console. That was years ago and a one off basically.
Why not ^Z and `fg`? (I'm sure that there's a subtle or not-so-subtle difference, but I've only ever suspended, never XOFF'd, so I don't know it.)
Not much of a console user then, maybe? Because, like, cat /something is useless without page control.
Oh, maybe you're a speedreader?
I never use flow control either, I just pipe it to less.
So my use of never might be hyperbolic, but it is a figure of speech. I can count on one hand with fingers leftover how often I've "needed" flow control. So just like in math, 0.99999 is equivalent functionally to 1 in this case.
I use CTRL+R and CTRL+S often in emacs and was frustrated that CTRL+S would not work on a command line terminal. As the article mentions, CTRL+S is typically interpreted as XON. Turning that off will enable forward search.
This is absolutely one of those things I've had happen once or twice a year, poke around in puzzlement for 5 minutes, and then just restart and get on with my day. You knew it was a keystroke but never quite followed through on tracking down what/how to fix. Quite nice to know what the hell was going on all this time :)
Probably you've used Control-C a few times, maybe Control-Z too .. well, these basic characters have a control function over your process' terminal input/output, just like ^M/^N (carriage return/line-feed), ^L (clear screen) and so on .. Just like Control-C is a shortcut for "Cancel" process.. C-S-Q is sort of the 'gearing' over process output, where Z, which is 'detach process i/o from console', otherwise known as "background the process", ( * ) might be considered the 'clutch'.
Anyway, C-S-Q .. those 4 keys control the process. Cancel, Stop, Quick.
Practice it a few times with some cat /somelargefile.txt paging and you'll see there's a use for it beyond perplexity. When 'less' and even 'more' are not around, Control-S/-Q are your trusty pals.
(* - Another "oh, fudge, dunno what happened, guess I'll just reboot.." moment can occur with errant Control-Z usage over a process, where you accidentally put the process in the background and don't know how to re-attach it. In that case, the command 'fg' is your friend .. I've see far too many experienced people not know they can put their processes back in place during debug/admin sessions, opting indeed to reboot, or at least restart the term session, that I can't help but feel that, like Stop/Quick, Control-Z+'fg' is somewhat of a lost lore..)
http://www.linusakesson.net/programming/tty/
It mentions what XON/XOFF, as well as what all the other control characters do.
Yeah, I'd be like, $!@*$%# Ubuntu :-)
in .vimrc
nn <C-s> :w<CR>
vn <C-s> :w<CR>
ino <C-s> <ESC>:w<CR>