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

Documentation is not so clear, I don't know how to proceed #900

Closed
santiagobasulto opened this issue Dec 14, 2022 · 4 comments
Closed

Documentation is not so clear, I don't know how to proceed #900

santiagobasulto opened this issue Dec 14, 2022 · 4 comments

Comments

@santiagobasulto
Copy link

I'm sorry in advance if this is a terribly n00b question. I have a jupyter server running, with a specific Notebook that has processed, and I'm trying to programmatically connect to it and execute some arbitrary code [0].

I know that somehow I have to get a BlockingKernelClient instance (and then use the execute or execute_interactive) potentially using a KernelManager but I just don't know how to do it.

I see everywhere that these managers receive a config, but I don't see much about it in the documentation.

If you could point me in the right direction I'd be glad to contribute some more documentation for more n00bs like me :)

[0] There is a dataframe in memory which has some partial state that I want to log/process. I need to get that intermediate state in memory of the dataframe that is always in the df variable.

So, I just need to somehow do (in pseudocode):

# using Jupyter Server API
kernel_id = find_kernel_id_for_notebook("MyNotebookRunning.ipynb")

# using jupyter-client
client = get_kernel(kernel_id=kernel_id)
result = client.execute("""
df.describe() # whatever
""")

# log the result
@davidbrochart
Copy link
Member

#811 could help.

@santiagobasulto
Copy link
Author

That was useful, thanks very much! After digging with Jupyter runtimes and the issue you linked I was able to instantiate a BlockingKernelClient and execute code in an arbitrary Kernel of my choice.

Is the BlockingKernelClient.execute() the preferred method to execute some code on that kernel and get the result?[0] Or should I use execute_interactive and capture stdout to get what I need.

Thanks!

[0] I see I receive a message ID of some sort, I assume I can then check the stdout/stderr of that message?

@davidbrochart
Copy link
Member

Maybe take inspiration from nbclient?

@santiagobasulto
Copy link
Author

Thanks, will do that, I think I can contribute some docs about runtimes now if that's ok with the project. I'll go ahead and close this issue. Thank you again @davidbrochart !

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

2 participants