jupyter - Communicating with Ipython kernel from a python script -
i want run commands sent python script ipython. read can done kernelmanager. so, tried below code found in site. if try addition in execute command, output in format: {u'text/plain': u'4'}. other command, print 'hi', empty data.
can me understand doing wrong or there better way setup client script , execute python commands in ipython.
from subprocess import pipe jupyter_client import kernelmanager import time try: queue import empty # py 3 except importerror: queue import empty # py 2 km = kernelmanager(kernel_name = 'python2') km.start_kernel() print km.is_alive() try: c = km.client() msg_id=c.execute('print "hi"') state='busy' data={} while state!='idle' , c.is_alive(): try: msg=c.get_iopub_msg(timeout=1) if not 'content' in msg: continue content = msg['content'] if 'data' in content: data=content['data'] if 'execution_state' in content: state=content['execution_state'] except empty: pass print data except keyboardinterrupt: pass finally: km.shutdown_kernel() print km.is_alive()
Comments
Post a Comment