add stdin to the notebook #3089

Merged
merged 13 commits into from Apr 26, 2013

Projects

None yet

2 participants

@minrk
Member
minrk commented Mar 27, 2013

adds a simple stdin handler to the notebook, so things like raw_input and %debug work.

%debug in action:

debug

This PR depends on #3011 and #3088. Incentive!

@minrk
Member
minrk commented Mar 27, 2013

The main thing remaining to do here is to prevent shift-enter from executing code while the raw_input filed is active. That can mess things up.

@ellisonbg
Member

Minor UI comments:

  • The text area used to type stdin should have the font properties as the regular monospace we are using, namely black.
  • We should probably think about how to size the width of the text area.
  • When a user hits return for stdin, it inserts a static version of the prompt and typed text below the input cell. This static version should have the same margins/padding as the actual prompt/text area, so there isn't a jump when a user presses return.
minrk added some commits Apr 6, 2013
@minrk minrk cleanup stdin event submission
follow example in rename notebook: remove form, bind keydown for enter,
avoiding shift-enter submitting the cell again.
5631528
@minrk minrk tweak raw-input styling
should fix alignment of raw_input and prompt
5a8093e
@ellisonbg ellisonbg and 1 other commented on an outdated diff Apr 25, 2013
IPython/frontend/html/notebook/handlers.py
@@ -507,6 +507,12 @@ def _inject_cookie_message(self, msg):
# under Python 2.x for some reason
msg = msg.encode('utf8', 'replace')
try:
+ bsession, msg = msg.split(':', 1)
@ellisonbg
ellisonbg Apr 25, 2013 IPython member

I think the identity should be handled at the level of the handler rather than in the JS code and sent to the handler.

@minrk
minrk Apr 25, 2013 IPython member

Discussed on HipChat, this isn't possible - the identity of the StdIn and Shell sockets must match for input_request routing, and the only thing that has a handle on both at the same time is the Javascript.

@ellisonbg
ellisonbg Apr 26, 2013 IPython member

The name "bsession" is a bit confusing. Can you rename the variable to emphasize that this is the socket identity and provide some comments reminding us why we have to pass this and what it is for.

@ellisonbg
Member

Shouldn't some of the channels have an on_message method that is different from the base class (like a pass)?

@ellisonbg
Member

I really like the cleanup/refactor of the zmq handlers. Much cleaner and easy to maintain. Amazing how simple it is!

@ellisonbg ellisonbg commented on the diff Apr 25, 2013
IPython/frontend/html/notebook/static/js/kernel.js
}
}, 1000);
- this.shell_channel.onmessage = $.proxy(this._handle_shell_reply,this);
- this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply,this);
+ this.shell_channel.onmessage = $.proxy(this._handle_shell_reply, this);
+ this.iopub_channel.onmessage = $.proxy(this._handle_iopub_reply, this);
+ this.stdin_channel.onmessage = $.proxy(this._handle_input_request, this);
@ellisonbg
ellisonbg Apr 25, 2013 IPython member

Maybe use stdin rather than input to be consistent in the naming?

@ellisonbg
ellisonbg Apr 25, 2013 IPython member

Also below...

@minrk
minrk Apr 25, 2013 IPython member

it's called an input_request, that's the message type. See our message spec

@ellisonbg ellisonbg commented on the diff Apr 25, 2013
IPython/frontend/html/notebook/static/js/kernel.js
@@ -433,6 +451,26 @@ var IPython = (function (IPython) {
};
+ Kernel.prototype._handle_input_request = function (e) {
+ var request = $.parseJSON(e.data);
+ var header = request.header;
+ var content = request.content;
+ var metadata = request.metadata;
+ var msg_type = header.msg_type;
+ if (msg_type !== 'input_request') {
@ellisonbg
ellisonbg Apr 25, 2013 IPython member

Then again, maybe "input" is better as it is the name of the message.

@minrk
minrk Apr 25, 2013 IPython member

it is a request, it has a reply, just like execute, etc.

@ellisonbg
Member

OK I have reviewed all of the code. Mostly minor comments and a bit of UI cleanup.

@minrk
Member
minrk commented Apr 25, 2013

When a user hits return for stdin, it inserts a static version of the prompt and typed text below the input cell. This static version should have the same margins/padding as the actual prompt/text area, so there isn't a jump when a user presses return.

I disagree - it should be a plain pre tag for this, but I'm not sure that I can make an input area with zero margins, so I don't think this is possible.

@minrk
Member
minrk commented Apr 26, 2013

I spoke too soon, the layout should match reasonably well now.

@ellisonbg
Member

OK, the look of the input area matches the pre quite well. Great work! Right now the input area is statically sized to 80 cols. When the notebook window is narrower than that, the layout gets messed up. It looks like it would be difficult to make it variable width. Do you think we need the full 80 cols for this?

@ellisonbg ellisonbg commented on an outdated diff Apr 26, 2013
IPython/frontend/html/notebook/handlers.py
@@ -507,6 +507,12 @@ def _inject_cookie_message(self, msg):
# under Python 2.x for some reason
msg = msg.encode('utf8', 'replace')
try:
+ bsession, msg = msg.split(':', 1)
+ self.session.session = bsession.decode('ascii')
+ except Exception:
+ logging.error("No bsession!", exc_info=True)
@ellisonbg
ellisonbg Apr 26, 2013 IPython member

This error message is a bit cryptic.

@ellisonbg
Member

Any response to the on_message behavior?

@minrk
Member
minrk commented Apr 26, 2013

As for 80 cols - no, I don't expect it to be needed often, but I don't know how to make it auto-width.

Sorry I didn't comment, but I did set the IOPub on_message to pass, since IOPub downstream messages don't make any sense.

I also fixed the bsession / error message when the first message is not given.

@ellisonbg ellisonbg merged commit c3a9044 into ipython:master Apr 26, 2013

1 check was pending

Details default The Travis build is in progress
@tkf tkf referenced this pull request in tkf/emacs-ipython-notebook Jun 11, 2013
Open

Implement stdin channel #115

@tkf tkf added a commit to tkf/emacs-ipython-notebook that referenced this pull request Jul 10, 2013
@tkf tkf Use IPython 1.0-compatible "handshake"
IPython changed the way to start channel [1].
fixes #121

[1] see commit ipython/ipython@24dcb6b
in ipython/ipython#3089
146fc45
@tkf tkf referenced this pull request in tkf/emacs-ipython-notebook Jul 10, 2013
Open

Use IPython 1.0-compatible "handshake" to open kernel channels #122

@minrk minrk deleted the minrk:stdin branch Mar 31, 2014
@v0dro v0dro referenced this pull request in SciRuby/iruby Nov 3, 2016
Open

Implement stdin #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment