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

Support {"msg_type":"shutdown_request"} and “quit()” for “ipython console” #153

Closed
flying-sheep opened this issue Jun 14, 2015 · 12 comments

Comments

@flying-sheep
Copy link
Member

start a R console with IPython frontend via ipython console --kernel=ir

pressing C-d will apparently send a {"msg_type":"shutdown_request"} message to the kernel. we should support those.

other methods to cleanly exit R like calling quit() should also work, but instead yield “kernel died, restart ([y]/n)?”

@takluyver
Copy link
Member

There is code to support shutdown_request - https://github.com/IRkernel/IRkernel/blob/0.4/R/kernel.r#L209

We should do the right thing when quit() is called, though. It's a bit convoluted: the kernel doesn't shut itself down, but the execute_reply it sends to the frontend includes an ask_exit payload. That will cause the frontend to issue a shutdown_request, and shut itself down as well.

@flying-sheep
Copy link
Member Author

@shutdown_request: apparently it needs to be handled in handle_shell:

$ ipython console --kernel=ir
IPython Console 3.1.0

In [1]: <C-d>
Do you really want to exit ([y]/n)? y
[1] "Got unhandled msg_type:" "shutdown_request"    

@takluyver
Copy link
Member

Ah, I bet the shutdown_request is coming over the shell channel instead of the control channel. Technically, the same set of messages can go over either channel. I guess I was testing it on the Qt console, and there shutdown_request actually goes over the control channel.

@flying-sheep
Copy link
Member Author

jup, if it can come via both, we need to handle it in both.

@flying-sheep
Copy link
Member Author

ah, quit() is still not there

@flying-sheep flying-sheep reopened this Oct 5, 2015
@jankatins
Copy link
Contributor

Yep, also just found out that quit() is not the way to exit a kernel...

Maybe overwrite the default quit function to call whatever the kernel needs tell the kernel manager to quit?

@flying-sheep
Copy link
Member Author

yes, but i think this is getting chaotic.

we need to structure everything to make clear how it works

  • options we set
  • functions and variables we insert into the namespace
  • functions we override/replace

@takluyver what do we do apart from those?

@takluyver
Copy link
Member

I don't think we currently inject anything into the user namespace. We inject one function of the IRdisplay namespace so that that can send data using the kernel.

In time we probably want to override quit() and readline() to use the kernel.

@flying-sheep
Copy link
Member Author

we are shading quit already.

but that breaks when clearing the global/user namespace, so maybe we should put it somewhere else. because yeah, it’s the user namespace, not ours.

@takluyver
Copy link
Member

Aha, I missed that ;-).

What namespace is quit() normally in? Can we replace it there? Or can we shadow it from the package's namespace?

@flying-sheep
Copy link
Member Author

What namespace is quit() normally in?

you can easily check that by doing

> environment(quit)
<environment: namespace:base>

Can we replace it there? Or can we shadow it from the package's namespace?

i think both. all packages are between .GlobalEnv and package:base, so wherever we put it it will work.

> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics" 
[4] "package:grDevices" "package:utils"     "package:datasets" 
[7] "package:methods"   "Autoloads"         "package:base" 

but we actually don’t attach any package, so we either

  1. need to attach IRkernel (which would expose its public functions),
  2. create and attach a IRoverrides package that contains just the functions we want to shade, or
  3. replace quit() in package:base

@flying-sheep
Copy link
Member Author

fixed ages ago in #196

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

No branches or pull requests

3 participants