(kc)
| 85 | |
| 86 | |
| 87 | def start_snakemq(kc): |
| 88 | global messaging |
| 89 | |
| 90 | messaging, link = utils.init_snakemq(config.IDENT_KERNEL_MANAGER, "connect") |
| 91 | logger.info(f"start_snakemq messaging: {messaging}") |
| 92 | |
| 93 | def on_recv(conn, ident, message): |
| 94 | logger.info(f"start_snakemq ident: {ident}") |
| 95 | if ident == config.IDENT_MAIN: |
| 96 | message = json.loads(message.data.decode("utf-8")) |
| 97 | logger.info("json.loads: %s" % message["value"]) |
| 98 | |
| 99 | if message["type"] == "execute": |
| 100 | logger.info("Executing command: %s" % message["value"]) |
| 101 | kc.execute(message["value"]) |
| 102 | # Try direct flush with default wait (0.2) |
| 103 | flush_kernel_msgs(kc) |
| 104 | |
| 105 | messaging.on_message_recv.add(on_recv) |
| 106 | |
| 107 | start_flusher(kc) |
| 108 | |
| 109 | # Send alive |
| 110 | utils.send_json(messaging, {"type": "status", "value": "ready"}, config.IDENT_MAIN) |
| 111 | logger.info("Python kernel ready to receive messages!") |
| 112 | |
| 113 | logger.info("Starting snakemq loop") |
| 114 | |
| 115 | try: |
| 116 | link.loop() |
| 117 | except KeyboardInterrupt: |
| 118 | logger.info("Keyboard interrupt received, exiting...") |
| 119 | sys.exit(0) |
| 120 | except Exception as e: |
| 121 | logger.error("Error in snakemq loop: %s" % e) |
| 122 | sys.exit(1) |
| 123 | |
| 124 | |
| 125 | def start_flusher(kc): |
no test coverage detected