Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions py-src/ltipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pickle
import json


def noop():
pass

Expand All @@ -24,15 +25,21 @@ def km_from_string(s=''):
or just 'kernel-12345.json' for IPython 0.12
"""
global km, kc, send, Empty

from os.path import join as pjoin

from IPython.config.loader import KeyValueConfigLoader
from Queue import Empty

if int(sys.version.split(' ')[0][0]) > 2:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it would be much easier to use sys.version_info[0] (that's already an integer)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, that was just something quick and dirty

from queue import Empty
else:
from Queue import Empty

try:
from IPython.kernel import (
KernelManager,
find_connection_file,
)

except ImportError:
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
from IPython.zmq.kernelapp import kernel_aliases
Expand All @@ -54,6 +61,7 @@ def km_from_string(s=''):
send = km.shell_channel.execute

respond(None, "python.client.error.ipython-version", None)

return


Expand Down Expand Up @@ -84,6 +92,7 @@ def msgId(m):
return m['parent_header']['msg_id']

def normalize(m):

mid = msgId(m)
content = m['content']

Expand Down Expand Up @@ -163,9 +172,17 @@ def msgloop():
global ipy
while not ipy.returncode and not ltmain.stopped():
for m in msgs():
#mw(str(time.time())+'\n','a')
#mw(str(m)+'\n\n','a')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are those function calls added, but commented out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tired to clean all those up before commit, looks like I missed some, they were just so that I could write some information out to a file to track down what the code was doing at various parts since it was being executed in a background python process. I had to figure out why it was failing to python instead of ipython

handleMsg(m)
time.sleep(0.01)

#def mw(string,mode):
#f = open('/Users/nate/Desktop/log_file.txt',mode)
#f.write(string)
#f.close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are those function calls added, but commented out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see note above, these are safe to remove completely



def initIPy(s):
try:
cur = km_from_string(s)
Expand All @@ -175,9 +192,11 @@ def initIPy(s):
disconnected()

loc = os.path.dirname(__file__)

send("import sys\nsys.path.append('" + loc.replace('\\','\\\\') + "')\nimport lttools")
connected()
msgloop()

disconnected()
except:
disconnected()
Expand All @@ -189,6 +208,7 @@ def IPyOutput(l):
m = re.search('--existing (.*\.json)', l)
if m:
initIPy(m.group(1))

if re.search('ImportError: IPython.zmq', l):
respond(None, "python.client.error.pyzmq", None)

Expand All @@ -201,13 +221,15 @@ def listenIPy():
disconnected()
break
IPyOutput(next_line)


def startIPy(opts):
global ipy
global respond
global disconnected
global connected
global km
global f
respond = opts["respond"]
connected = opts["connected"]
disconnected = opts["disconnected"]
Expand All @@ -228,6 +250,8 @@ def startIPy(opts):
disconnected()
return None



def killIPy():
global ipy
try:
Expand Down
6 changes: 4 additions & 2 deletions py-src/ltmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ def start(type):
sys.stdout.flush()
info["type"] = type
s.send((json.dumps(info)+ "\n").encode('utf-8'));

sys.stdout = Printer()
sys.stderr = Printer()


asyncore.loop()

def connected():
Expand Down Expand Up @@ -403,6 +403,7 @@ def sendoff(self, msg):
curDir = os.getcwd()
sys.path.append(curDir)
name = os.path.basename(curDir)
#global info

try:
cid = int(sys.argv[2])
Expand All @@ -418,4 +419,5 @@ def sendoff(self, msg):
ltipy.startIPy({"respond": send,
"connected": connected,
"disconnected": disconnected})
#disconnected()
#disconnected()

18 changes: 16 additions & 2 deletions py-src/lttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,30 @@ def watch(exp, meta):
sys.stdout.write("__WATCH " + pickle.dumps({"meta": meta, "result": pp.pformat(exp)}))
return exp

def factory():
import imp
NewClass = imp.new_module('')
return NewClass

def toModule(path):
name = toModuleNameByPath(path)
if name in sys.modules:
return sys.modules[name]
else:
#not sure what the loop is for as the exec only cared about name and not mname
#ignored this for now
parts = name.split(".")
for idx in range(len(parts)):
mname = ".".join(parts[:idx+1])
__import__(mname)
exec("import sys", sys.modules[name].__dict__)
#__import__(mname)
dummy = factory()
dummy.__name__ = name
#exec("import sys", sys.modules[name].__dict__)
#not sure why these were exec statements and not just normal statements
#but I followed the same pattern below
exec('import sys')
exec('sys.modules[name] = dummy')
exec('import sys', sys.modules[name].__dict__)
return sys.modules[name]

def switch_ns(path):
Expand Down