Created
September 23, 2018 00:29
-
-
Save andrewssobral/bd0f0d384c0e7aada66a6454767076f3 to your computer and use it in GitHub Desktop.
Jupyter Client (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jupyter_client.kernelspec import NATIVE_KERNEL_NAME | |
from jupyter_client.manager import start_new_kernel | |
km, kc = start_new_kernel(kernel_name=NATIVE_KERNEL_NAME) | |
def run_cell(client, code, timeout=15): | |
print("\nrunning: ", code) | |
reply = client.execute_interactive(code, timeout=timeout) | |
status = reply['content']['status'] | |
if status == 'ok': | |
print('succeeded!') | |
elif status == 'error': | |
print('failed!') | |
for line in reply['content']['traceback']: | |
print(line) | |
run_cell(kc, "result='Hello world!'") | |
run_cell(kc, "print(result)") | |
kc.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment