In [1]:
from IPython.lib.kernel import find_connection_file
from IPython.kernel import BlockingKernelClient
import os

In [19]:
cf = '/home/epilib/Envs/env1/.ipython/profile_default/security/kernel-c5bd6be3-7df6-4b6f-8289-4d54908e39db.json'

In [2]:
cf = '/home/usgs/.ipython/profile_default/security/kernel-632e13a5-00f5-422c-9588-34b195bc2349.json'

In [3]:
km = BlockingKernelClient(connection_file=cf)

In [4]:
km.load_connection_file()

In [5]:
km.start_channels()

In [6]:
def run_cell(km, code):
    # now we can run code.  This is done on the shell channel
    shell = km.shell_channel
    print
    print "running:"
    print code
    # execution is immediate and async, returning a UUID
    msg_id = shell.execute(code)
    # get_msg can block for a reply
    reply = shell.get_msg()

    status = reply['content']['status']
    if status == 'ok':
        print 'succeeded!'
    elif status == 'error':
        print 'failed!'
        for line in reply['content']['traceback']:
            print line

In [9]:
run_cell(km, 'a=5')


running:
print len(good_data2)
failed!
  File "<ipython-input-38-dc8a7e818e6f>", line 1
    print len(good_data2)
            ^
SyntaxError: invalid syntax


In [8]:
print len(good_data2)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-dc8a7e818e6f> in <module>()
----> 1 print len(good_data2)

NameError: name 'good_data2' is not defined

In [ ]:
run_cell()