jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.72k stars 4.96k forks source link

Ctrl-c doesn't seem to work in web terminal #1227

Open praveen-srinivasan opened 8 years ago

praveen-srinivasan commented 8 years ago

This is Jupyter notebook server 4.1.0

Ctrl-c doesn't seem to do what I would expect, e.g. if I do something like "tail -f foo" and then hit "ctrl-c", it doesn't exit "tail". It just prints "^C" on the screen.

takluyver commented 8 years ago

Works for me. What OS & browser are you on?

praveen-srinivasan commented 8 years ago

Mac OS X, Chrome (also doesn't work in Safari)

yuvipanda commented 8 years ago

Same as https://github.com/jupyter/notebook/issues/104 I think?

takluyver commented 8 years ago

I think #104 is about copy/paste, and this is about interrupting programs using Ctrl-C. Both are likely terminado issues rather than something we can fix, though there's a small chance that this is something on our side.

alouisos commented 8 years ago

Reporting the same issue on Mac OS Chrome terminals. Cannot interrupt process in terminal with Ctrl+C

kingjr commented 8 years ago

Same problem with with Ubuntu 14.04 & Firefox.

gnestor commented 8 years ago

I have verified that ^C is successfully interrupting a process using Chrome on OS X.

Screenshot:

screenshot

ricardobarroslourenco commented 8 years ago

I'm under the same issue, using MacOS El Capitan...

oolongknits commented 7 years ago

I had the same problem and (at least in my case) this is a problem with the terminal shortcuts.

I'm on Linux and in the terminal I did: Edit -> Preferences -> Shortcuts I found Ctr+C was a shortcut to Copy. I changed it to something else and now it works as it is supposed to.

oschuett commented 7 years ago

Maybe the Jupyter terminal should overwrite some of the browser's default shortcuts: https://stackoverflow.com/questions/3680919/overriding-browsers-keyboard-shortcuts

gnestor commented 7 years ago

I should add that it's working for me using Chrome on MacOS Sierra.

I understand that CTRL+C on Windows is copy and I don't think there is anything we can do to override that, but I'm curious what shortcut do you use to kill a process in the Window's terminal? Linux?

oschuett commented 7 years ago

I'm using Chrome under Linux and there it's not working either for the same reason. Hence, my proposal to prevent the default event handling in these cases.

gnestor commented 7 years ago

But what if you want to copy something from the terminal output?

takluyver commented 7 years ago

On Linux, GUI Ctrl shortcuts typically become Ctrl-Shift in a terminal - Ctrl-Shift-C for copy, Ctrl-Shift-N for new window. It's up to the terminal emulator, though. That leaves shortcuts like Ctrl-C for sending control characters to the terminal (which the pty may then translate into signals, e.g. SIGINT).

The default command prompt in Windows doesn't have shortcuts for things like 'copy', as far as I know - you have to initiate copying with the mouse. I'm not sure what other Windows terminal emulators do.

gnestor commented 7 years ago

@takluyver Any ideas on how to resolve this for Windows users?

takluyver commented 7 years ago

Resolve what? It should work the same for users running the browser in Windows against a Unix server, and the terminal isn't supported when the server runs on Windows.

gnestor commented 7 years ago

Ok, I wasn't sure if the terminal is the notebook was working as expected or not. So nothing needs to be done then?

takluyver commented 7 years ago

It sounds like there is a problem for some people, but it's not clear under what conditions it occurs.

The behaviour I'd expect in a terminal is:

  1. Ctrl-C is delivered to the terminal, where it will typically be translated into SIGINT.
  2. If the frontend (terminal emulator) is in Linux or Windows, Ctrl-Shift-C copies to the clipboard.
  3. Other platform copy shortcuts, such as Cmd-C on OS X and Ctrl-Insert on Linux, should work as normal.

Browser limitations may prevent us from implementing 2, because we can only access the clipboard when the browser's own mechanisms handle a clipboard shortcut. But it sounds like there are some problems with 1.

This is probably an issue with xterm.js, and it may already be fixed, either in a version we've already bundled into Jupyter since it was reported, or a still newer version. But without a reliable way to reproduce it, we don't really know.

gnestor commented 7 years ago

Ok, thanks for breaking this down, @takluyver. I guess it wouldn't hurt to bump our xterm.js dependency in the notebook. I'll do that now....

I took a look at the xterm repo and there doesn't seem to be any outstanding issues or recently submitted PRs regarding using CTRL-C or SIGINT, but there was Fix Ctrl+Shift+V pasting.

rjurney commented 6 years ago

This still exists and is not fixed. This is a serious problem for me... I can't have students exit their Flask Python programs they run in terminals. CTRL-Z works, CTRL-C does nothing but print '^C'. I am on OS X in Chrome. It also happens in Firefox and Safari.

Does anyone have ideas? I could even try to fix this if someone can tell me what needs fixing.

dhirschfeld commented 6 years ago

On Windows Ctrl-Break is often used for terminating processes, but so is Ctrl-C

takluyver commented 6 years ago

Unfortunately we haven't figured out what needs fixing - we can't reproduce the problem, so it's hard to investigate.

Now that terminals are supported when Windows is on the backend as well, there may be a bug there.

If you can reproduce the problem, can you try:

liucimin commented 4 years ago

This still exists and is not fixed.

lleeoo commented 4 years ago

I've found a way to rep both the correct and the incorrect behaviour.

Exec summary

Ctrl+C fails when I start jupyter remotely via ssh.

Versions

Jupyter 6.0.3, Python 3.7.7, RHEL 6 or 7.

Details

If I ssh to the server directly, run jupyter, then log out, Ctrl+C interrupts programs:

nohup "jupyter notebook --no-browser" < /dev/null > $remote_tmp_file 2>&1 &

However, if I try executing the exact same command from my machine, via ssh -q then Ctrl+C doesn't work:

ssh -q "nohup jupyter notebook --no-browser < /dev/null > $remote_tmp_file 2>&1 &"

AFAIK everything else works. stty -a is identical.

I have to try now with tmux to see if there is a way to retain the remote start functionality.

AlexGuo1998 commented 3 years ago

However, if I try executing the exact same command from my machine, via ssh -q then Ctrl+C doesn't work:

ssh -q "nohup jupyter notebook --no-browser < /dev/null > $remote_tmp_file 2>&1 &"

It's even easier to reproduce. Create run.sh as below:

#!/bin/sh
nohup jupyter notebook >jupyter.log 2>&1 &

Remember to chmod u+x run.sh

Now try:

./run.sh

... and Ctrl-C is broken in terminal

Alternatively, kill previous notebook and try:

source ./run.sh

... then Ctrl-C works correctly!