Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SIGINT handler to not use the old interactive shell API #80

Merged
merged 2 commits into from
Jun 2, 2016

Conversation

adrianliaw
Copy link
Contributor

Currently, when using Ctrl-C on the console that connects to an existing kernel, it raises an error:

Traceback (most recent call last):
  File "/Users/adrianliaw/.pyenv/versions/py351/bin/jupyter-console", line 9, in <module>
    load_entry_point('jupyter-console', 'console_scripts', 'jupyter-console')()
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_core/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/Users/adrianliaw/.pyenv/versions/py351/lib/python3.5/site-packages/traitlets/config/application.py", line 596, in launch_instance
    app.start()
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/app.py", line 150, in start
    self.shell.mainloop()
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/ptshell.py", line 462, in mainloop
    self.interact()
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/ptshell.py", line 454, in interact
    self.run_cell(code, store_history=True)
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/ptshell.py", line 505, in run_cell
    self.handle_input_request(msg_id, timeout=0.05)
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/ptshell.py", line 757, in handle_input_request
    req = self.client.stdin_channel.get_msg(timeout=timeout)
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_client/jupyter_client/blocking/channels.py", line 50, in get_msg
    ready = self.socket.poll(timeout)
  File "/Users/adrianliaw/.pyenv/versions/py351/lib/python3.5/site-packages/zmq/sugar/socket.py", line 503, in poll
    evts = dict(p.poll(timeout))
  File "/Users/adrianliaw/.pyenv/versions/py351/lib/python3.5/site-packages/zmq/sugar/poll.py", line 99, in poll
    return zmq_poll(self.sockets, timeout=timeout)
  File "zmq/backend/cython/_poll.pyx", line 122, in zmq.backend.cython._poll.zmq_poll (zmq/backend/cython/_poll.c:1850)
  File "zmq/backend/cython/_poll.pyx", line 115, in zmq.backend.cython._poll.zmq_poll (zmq/backend/cython/_poll.c:1705)
  File "zmq/backend/cython/checkrc.pxd", line 12, in zmq.backend.cython.checkrc._check_rc (zmq/backend/cython/_poll.c:2084)
  File "/Users/adrianliaw/Documents/projects/fork/jupyter_console/jupyter_console/app.py", line 122, in handle_sigint
    self.shell.write_err('\n')
AttributeError: 'ZMQTerminalInteractiveShell' object has no attribute 'write_err'

Clearly that app.py used an outdated API on ZMQTerminalInteractiveShell, this pull request fixed this.

@@ -119,7 +120,7 @@ def handle_sigint(self, *args):
if self.kernel_manager:
self.kernel_manager.interrupt_kernel()
else:
self.shell.write_err('\n')
print("\n", file=sys.stderr, end="\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will now print two newlines, whereas it was only one before. Can one of them be removed?

@takluyver
Copy link
Member

Thanks, good catch. ZMQTerminalInteractiveShell used to inherit from IPython's InteractiveShell class, where that method was defined.

@adrianliaw
Copy link
Contributor Author

@takluyver I just made a commit that removes the redundant line in the print statement, thanks!

@@ -142,7 +143,7 @@ def init_banner(self):
self.shell.show_banner()
# Make sure there is a space below the banner.
if self.log_level <= logging.INFO: print()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, in general we ask people to configure their editor not to strip whitespace, because it inflates diffs and can lead to spurious merge conflicts. It doesn't matter much when it's only a few lines like here, but it's good to bear in mind if you contribute bigger changes. :-)

@takluyver takluyver merged commit 3b83499 into jupyter:master Jun 2, 2016
@takluyver
Copy link
Member

Thanks! 🍪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants