##// END OF EJS Templates
Allow argv and namespace control to be passed to engines/controller.
Fernando Perez -
Show More
@@ -802,7 +802,7 b' def make_argument_parser():'
802 802
803 803 return parser
804 804
805 def main():
805 def main(argv=None):
806 806 import time
807 807 from multiprocessing import Process
808 808
@@ -816,7 +816,7 b' def main():'
816 816
817 817 parser = make_argument_parser()
818 818
819 args = parser.parse_args()
819 args = parser.parse_args(argv)
820 820 parse_url(args)
821 821
822 822 iface="%s://%s"%(args.transport,args.ip)+':%i'
@@ -39,8 +39,10 b' class Engine(object):'
39 39 registrar=None
40 40 heart=None
41 41 kernel=None
42 user_ns=None
42 43
43 def __init__(self, context, loop, session, registrar, client=None, ident=None):
44 def __init__(self, context, loop, session, registrar, client=None, ident=None,
45 heart_id=None, user_ns=None):
44 46 self.context = context
45 47 self.loop = loop
46 48 self.session = session
@@ -48,6 +50,7 b' class Engine(object):'
48 50 self.client = client
49 51 self.ident = ident if ident else str(uuid.uuid4())
50 52 self.registrar.on_send(printer)
53 self.user_ns = user_ns
51 54
52 55 def register(self):
53 56
@@ -78,8 +81,14 b' class Engine(object):'
78 81 sub.on_recv(lambda *a: None)
79 82 port = sub.bind_to_random_port("tcp://%s"%LOCALHOST)
80 83 iopub_addr = "tcp://%s:%i"%(LOCALHOST,12345)
81 make_kernel(self.ident, control_addr, shell_addrs, iopub_addr, hb_addrs,
82 client_addr=None, loop=self.loop, context=self.context, key=self.session.key)
84
85 k = make_kernel(self.ident, control_addr, shell_addrs, iopub_addr,
86 hb_addrs, client_addr=None, loop=self.loop,
87 context=self.context, key=self.session.key)[-1]
88 self.kernel = k
89 if self.user_ns is not None:
90 self.user_ns.update(self.kernel.user_ns)
91 self.kernel.user_ns = self.user_ns
83 92
84 93 else:
85 94 # logger.error("Registration Failed: %s"%msg)
@@ -100,11 +109,11 b' class Engine(object):'
100 109
101 110
102 111
103 def main():
112 def main(argv=None, user_ns=None):
104 113
105 114 parser = make_base_argument_parser()
106 115
107 args = parser.parse_args()
116 args = parser.parse_args(argv)
108 117
109 118 parse_url(args)
110 119
@@ -127,7 +136,11 b' def main():'
127 136 reg = zmqstream.ZMQStream(reg, loop)
128 137 client = None
129 138
130 e = Engine(ctx, loop, session, reg, client, args.ident)
139 e = Engine(ctx, loop, session, reg, client, args.ident, user_ns=user_ns)
131 140 dc = ioloop.DelayedCallback(e.start, 100, loop)
132 141 dc.start()
133 loop.start() No newline at end of file
142 loop.start()
143
144 # Execution as a script
145 if __name__ == '__main__':
146 main()
@@ -419,5 +419,5 b' def make_kernel(identity, control_addr, shell_addrs, iopub_addr, hb_addrs,'
419 419 shell_streams=shell_streams, iopub_stream=iopub_stream,
420 420 client=client)
421 421 kernel.start()
422 return loop, c
422 return loop, c, kernel
423 423
General Comments 0
You need to be logged in to leave comments. Login now