stop python in terminal on mac

前端 未结 2 1450
闹比i
闹比i 2021-01-03 22:19

Using python in terminal on a Mac, type

ctrl-z

will stop the python, but not exit it, giving output like this:

>>>         


        
2条回答
  •  余生分开走
    2021-01-03 23:07

    This isn't a Python issue, per se. This ia a Unix shell behavior and is a difference from Windows and other systems. See the Wikipedia article on CTRL-Z for a more complete explanation:

    On Unix-like systems, Control+Z is the most common default keyboard mapping for the key sequence that suspends a process (SIGTSTP). When entered by a user at their computer terminal, the currently running foreground process is sent a SIGTSTP signal, which generally causes the process to suspend its execution. The user can later continue the process execution by typing the command 'fg' (short for foreground) or by typing 'bg' (short for background) and furthermore typing the command 'disown' to separate the background process from the terminal.

    On OS X as on various other Unix-based systems, you could use the stty command to change which key, if any, produces a SIGTSTP (or an eof, for that matter):

    $ stty -a
    speed 38400 baud; 30 rows; 90 columns;
    lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc
    iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
        -ignbrk brkint -inpck -ignpar -parmrk
    oflags: opost onlcr -oxtabs -onocr -onlret
    cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
        -dtrflow -mdmbuf
    cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = ;
        eol2 = ; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
        min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
        stop = ^S; susp = ^Z; time = 0; werase = ^W;
    $ stty susp ^Y
    $ cat
    ^Y
    [1]+  Stopped                 cat
    

提交回复
热议问题