Python and EOF

raf macports at raf.org
Tue Mar 23 23:11:56 UTC 2021


On Tue, Mar 23, 2021 at 05:24:24PM +0000, Richard Tobin <richard at inf.ed.ac.uk> wrote:

> Is it possible to make python behave correctly when the user's EOF
> character is not set to control-D?  It works fine on Linux, but not
> with the macports on the Mac.
> 
> For historical reasons I have control-Z as my EOF character.  But
> typing it in python results in it being suspended rather than
> exiting.  Typing control-D just echoes ^D.
> 
> As I understand it, this is because python in macports uses libedit
> (aka editline) rather than readline.  Readline adjusts the key
> bindings to match the user's stty settings, but libedit doesn't.
> 
> Does anyone have a workaround for this?
> 
> -- Richard

Hi,

Are you sure it's Python? Ctrl-Z is the key for putting
the current process group into the background in shells
that support job-control. Maybe it's the shell doing
it.

What happens when you run "cat", type a few lines, then
press Ctrl-Z? Is cat suspended as well? If so, you
might need to also reconfigure your shell to use a
different key for suspending processes.

It is possible for programs to query the EOF character
when there's a pseudo terminal involved (tcgetattr() ->
attr.c_cc[VEOF]), though many might not think to do so.
But I would expect readline to handle EOF properly. But
I don't know for a fact that it does.

cheers,
raf



More information about the macports-users mailing list