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

Create a kernel with specified custom ports #955

Open
jkitchin opened this issue Jul 5, 2023 · 6 comments
Open

Create a kernel with specified custom ports #955

jkitchin opened this issue Jul 5, 2023 · 6 comments

Comments

@jkitchin
Copy link
Contributor

jkitchin commented Jul 5, 2023

I am trying to start a jupyter kernel like this:

jupyter-kernel \
       --ip=0.0.0.0 \
       --KernelManager.control_port=56406 \
       --KernelManager.hb_port=56407 \
       --KernelManager.iopub_port=56408 \
       --KernelManager.shell_port=56409 \
       --KernelManager.stdin_port=56410

It starts, and I see this output:

[KernelApp] Starting kernel 'python3'
[KernelApp] Connection file: /Users/jkitchin/Library/Jupyter/runtime/kernel-892382b5-8115-44ba-95cd-d8172ba848ac.json
however, the kernel json contains:

cat /Users/jkitchin/Library/Jupyter/runtime/kernel-892382b5-8115-44ba-95cd-d8172ba848ac.json
{
  "shell_port": 55505,
  "iopub_port": 55506,
  "stdin_port": 55507,
  "control_port": 55509,
  "hb_port": 55508,
  "ip": "0.0.0.0",
  "key": "0a163fda-2b4963c994abc4277bdf58fa",
  "transport": "tcp",
  "signature_scheme": "hmac-sha256",
  "kernel_name": ""
}

which do not match the ports I specified. Am I missing something to make this happen?

@kevin-bates
Copy link
Member

This is due to the KernelManager.cache_ports value of True (which is the trait's default for transport == tcp). Unfortunately, this trait is not marked as configurable, so I'm not sure there's a way to adjust this from a configuration file or the command line. I raised this concern a few years ago (after the port caching feature was implemented) but it was never addressed.

I see now that this is a duplicate of #878.

@jkitchin
Copy link
Contributor Author

jkitchin commented Jul 6, 2023

I can confirm the issue is with KernelManager.cache_ports. Thanks for the tip. At emacs-jupyter/jupyter#481 (comment) I patched this and then it works as one would expect it to. I don't know if it is a general solution for others who want to use this, but it probably beats forking it.

@kevin-bates
Copy link
Member

Hi @jkitchin - thanks for taking a closer look.

I think we can make cache_ports configurable by adding the config=True keyword argument into its "declaration" on L185 and similar to the shutdown_wait_time declaration. For completeness, we might as well add the default value of False argument prior to config=True.

This would then enable the use of --KernelManager.cache_ports=False on your command line, allowing custom port definitions to occur.

Would you like to contribute that pull request? It would resolve both this issue and #878, so it would a desirable change.

jkitchin pushed a commit to jkitchin/jupyter_client that referenced this issue Jul 6, 2023
@jkitchin
Copy link
Contributor Author

jkitchin commented Jul 6, 2023

I made a pull request above. I have tested it locally, and it seems to do the right things. The logic is confusing to me though. The default is set to False, but if you don't set --KernelManager.cache_ports=False then it does cache the ports, and if you do set that, it does not cache the ports.

@kevin-bates
Copy link
Member

The logic is confusing to me though. The default is set to False, but if you don't set --KernelManager.cache_ports=False then it does cache the ports, and if you do set that, it does not cache the ports.

Welcome to traitlets. This package does some magic stuff. In this case, there's already a "defaults handler" which overrides the False default with its return value. I hesitated suggesting adding the explicit False indicator, but I find it a more complete declaration, fwiw. This is why ONLY setting CLI option (or configuring that option via a configuration file) will appear to not cache the ports (when using transport==tcp, which is the transport trait's default).

@genatin
Copy link

genatin commented Sep 8, 2023

This is due to the KernelManager.cache_ports value of True (which is the trait's default for transport == tcp). Unfortunately, this trait is not marked as configurable, so I'm not sure there's a way to adjust this from a configuration file or the command line. I raised this concern a few years ago (after the port caching feature was implemented) but it was never addressed.

I see now that this is a duplicate of #878.

Yeah, it's customizable right now. Thanks, man

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

No branches or pull requests

3 participants