##// END OF EJS Templates
Fix iopubwatcher example script.
Blake Griffith -
Show More
@@ -14,35 +14,29 b' Authors'
14 * MinRK
14 * MinRK
15 """
15 """
16
16
17 import os
18 import sys
17 import sys
19 import json
18 import json
20 import zmq
19 import zmq
21
20
22 from IPython.kernel.zmq.session import Session
21 from IPython.kernel.zmq.session import Session
23 from IPython.parallel.util import disambiguate_url
24 from IPython.utils.py3compat import str_to_bytes
22 from IPython.utils.py3compat import str_to_bytes
25 from IPython.utils.path import get_security_file
23 from IPython.utils.path import get_security_file
26
24
27 def main(connection_file):
25 def main(connection_file):
28 """watch iopub channel, and print messages"""
26 """watch iopub channel, and print messages"""
29
27
30 ctx = zmq.Context.instance()
28 ctx = zmq.Context.instance()
31
29
32 with open(connection_file) as f:
30 with open(connection_file) as f:
33 cfg = json.loads(f.read())
31 cfg = json.loads(f.read())
34
32
35 location = cfg['location']
33 reg_url = cfg['interface']
36 reg_url = cfg['url']
34 iopub_port = cfg['iopub']
37 session = Session(key=str_to_bytes(cfg['exec_key']))
35 iopub_url = "%s:%s"%(reg_url, iopub_port)
38
36
39 query = ctx.socket(zmq.DEALER)
37 session = Session(key=str_to_bytes(cfg['key']))
40 query.connect(disambiguate_url(cfg['url'], location))
41 session.send(query, "connection_request")
42 idents,msg = session.recv(query, mode=0)
43 c = msg['content']
44 iopub_url = disambiguate_url(c['iopub'], location)
45 sub = ctx.socket(zmq.SUB)
38 sub = ctx.socket(zmq.SUB)
39
46 # This will subscribe to all messages:
40 # This will subscribe to all messages:
47 sub.setsockopt(zmq.SUBSCRIBE, b'')
41 sub.setsockopt(zmq.SUBSCRIBE, b'')
48 # replace with b'' with b'engine.1.stdout' to subscribe only to engine 1's stdout
42 # replace with b'' with b'engine.1.stdout' to subscribe only to engine 1's stdout
General Comments 0
You need to be logged in to leave comments. Login now