# sub.setsockopt(zmq.SUBSCRIBE, b'engine.2.stdout') sub.connect(iopub_url) while True: try: idents, msg = session.recv(sub, mode=0) except KeyboardInterrupt: return # ident always length 1 here topic = idents[0] if msg["msg_type"] == "stream": # stdout/stderr # stream names are in msg['content']['name'], if you want to handle # them differently print "%s: %s" % (topic, msg["content"]["data"]) elif msg["msg_type"] == "pyerr": # Python traceback c = msg["content"] print topic + ":" for line in c["traceback"]: # indent lines print " " + line if __name__ == "__main__": if len(sys.argv) > 1: cf = sys.argv[1] else: # This gets the security file for the default profile: cf = get_security_file("ipcontroller-client.json") main(cf)
# stdout: sub.setsockopt(zmq.SUBSCRIBE, b'engine.1.stderr') # sub.setsockopt(zmq.SUBSCRIBE, b'engine.2.stdout') sub.connect(iopub_url) while True: try: idents, msg = session.recv(sub, mode=0) except KeyboardInterrupt: return # ident always length 1 here topic = idents[0] if msg['msg_type'] == 'stream': # stdout/stderr # stream names are in msg['content']['name'], if you want to handle # them differently print("%s: %s" % (topic, msg['content']['data'])) elif msg['msg_type'] == 'pyerr': # Python traceback c = msg['content'] print(topic + b':') for line in c['traceback']: # indent lines print(' ' + line) if __name__ == '__main__': if len(sys.argv) > 1: cf = sys.argv[1] else: # This gets the security file for the default profile: cf = get_security_file('ipcontroller-client.json') main(cf)