Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow argv and namespace control to be passed to engines/controller.

  • Loading branch information...
commit cde7916ea31825ddf88a28f1b567bdac41d5419f 1 parent 1160d9f
@fperez fperez authored minrk committed
View
4 IPython/zmq/parallel/controller.py 100644 → 100755
@@ -802,7 +802,7 @@ def make_argument_parser():
return parser
-def main():
+def main(argv=None):
import time
from multiprocessing import Process
@@ -816,7 +816,7 @@ def main():
parser = make_argument_parser()
- args = parser.parse_args()
+ args = parser.parse_args(argv)
parse_url(args)
iface="%s://%s"%(args.transport,args.ip)+':%i'
View
27 IPython/zmq/parallel/engine.py 100644 → 100755
@@ -39,8 +39,10 @@ class Engine(object):
registrar=None
heart=None
kernel=None
+ user_ns=None
- def __init__(self, context, loop, session, registrar, client=None, ident=None):
+ def __init__(self, context, loop, session, registrar, client=None, ident=None,
+ heart_id=None, user_ns=None):
self.context = context
self.loop = loop
self.session = session
@@ -48,6 +50,7 @@ def __init__(self, context, loop, session, registrar, client=None, ident=None):
self.client = client
self.ident = ident if ident else str(uuid.uuid4())
self.registrar.on_send(printer)
+ self.user_ns = user_ns
def register(self):
@@ -78,8 +81,14 @@ def complete_registration(self, msg):
sub.on_recv(lambda *a: None)
port = sub.bind_to_random_port("tcp://%s"%LOCALHOST)
iopub_addr = "tcp://%s:%i"%(LOCALHOST,12345)
- make_kernel(self.ident, control_addr, shell_addrs, iopub_addr, hb_addrs,
- client_addr=None, loop=self.loop, context=self.context, key=self.session.key)
+
+ k = make_kernel(self.ident, control_addr, shell_addrs, iopub_addr,
+ hb_addrs, client_addr=None, loop=self.loop,
+ context=self.context, key=self.session.key)[-1]
+ self.kernel = k
+ if self.user_ns is not None:
+ self.user_ns.update(self.kernel.user_ns)
+ self.kernel.user_ns = self.user_ns
else:
# logger.error("Registration Failed: %s"%msg)
@@ -100,11 +109,11 @@ def start(self):
-def main():
+def main(argv=None, user_ns=None):
parser = make_base_argument_parser()
- args = parser.parse_args()
+ args = parser.parse_args(argv)
parse_url(args)
@@ -127,7 +136,11 @@ def main():
reg = zmqstream.ZMQStream(reg, loop)
client = None
- e = Engine(ctx, loop, session, reg, client, args.ident)
+ e = Engine(ctx, loop, session, reg, client, args.ident, user_ns=user_ns)
dc = ioloop.DelayedCallback(e.start, 100, loop)
dc.start()
- loop.start()
+ loop.start()
+
+# Execution as a script
+if __name__ == '__main__':
+ main()
View
2  IPython/zmq/parallel/streamkernel.py
@@ -419,5 +419,5 @@ def make_kernel(identity, control_addr, shell_addrs, iopub_addr, hb_addrs,
shell_streams=shell_streams, iopub_stream=iopub_stream,
client=client)
kernel.start()
- return loop, c
+ return loop, c, kernel
Please sign in to comment.
Something went wrong with that request. Please try again.