| 215 | return {"ok": False, "error": f"unsupported command: {cmd}"} |
| 216 | |
| 217 | def serve(self): |
| 218 | context = zmq.Context() |
| 219 | socket = context.socket(zmq.REP) |
| 220 | socket.bind(self.bind_addr) |
| 221 | try: |
| 222 | while self._running: |
| 223 | try: |
| 224 | msg = socket.recv_pyobj() |
| 225 | if not isinstance(msg, dict): |
| 226 | socket.send_pyobj({"ok": False, "error": "request must be a dict"}) |
| 227 | continue |
| 228 | reply = self.handle(msg) |
| 229 | except Exception as exc: |
| 230 | reply = {"ok": False, "error": str(exc)} |
| 231 | socket.send_pyobj(reply) |
| 232 | finally: |
| 233 | socket.close(0) |
| 234 | context.term() |
| 235 | for pid in list(self._managed.keys()): |
| 236 | self._terminate_pid(pid, timeout_seconds=2.0) |
| 237 | |
| 238 | |
| 239 | def main(): |