Start RPC tracker on a separate process. Python implementation based on PopenWorker. Parameters ---------- host : str The host url of the server. port : int The TCP port to be bind to port_end : int, optional The end TCP port to search silent:
| 455 | |
| 456 | |
| 457 | class Tracker: |
| 458 | """Start RPC tracker on a separate process. |
| 459 | |
| 460 | Python implementation based on PopenWorker. |
| 461 | |
| 462 | Parameters |
| 463 | ---------- |
| 464 | host : str |
| 465 | The host url of the server. |
| 466 | |
| 467 | port : int |
| 468 | The TCP port to be bind to |
| 469 | |
| 470 | port_end : int, optional |
| 471 | The end TCP port to search |
| 472 | |
| 473 | silent: bool, optional |
| 474 | Whether run in silent mode |
| 475 | |
| 476 | reuse_addr: bool, optional |
| 477 | Allows the kernel to reuse a local socket in TIME_WAIT state. |
| 478 | |
| 479 | timeout: float, optional |
| 480 | set a timeout for all operations on the socket |
| 481 | |
| 482 | """ |
| 483 | |
| 484 | def __init__( |
| 485 | self, host="0.0.0.0", port=9190, port_end=9199, silent=False, reuse_addr=True, timeout=None |
| 486 | ): |
| 487 | if silent: |
| 488 | logger.setLevel(logging.WARN) |
| 489 | self.proc = PopenWorker() |
| 490 | # send the function |
| 491 | self.proc.send( |
| 492 | _popen_start_tracker_server, [host, port, port_end, silent, reuse_addr, timeout] |
| 493 | ) |
| 494 | # receive the port |
| 495 | self.port, self.stop_key = self.proc.recv() |
| 496 | self.host = host |
| 497 | |
| 498 | def _stop_tracker(self): |
| 499 | sock = socket.socket(base.get_addr_family((self.host, self.port)), socket.SOCK_STREAM) |
| 500 | sock.connect(("127.0.0.1", self.port)) |
| 501 | sock.sendall(struct.pack("<i", base.RPC_TRACKER_MAGIC)) |
| 502 | magic = struct.unpack("<i", base.recvall(sock, 4))[0] |
| 503 | assert magic == base.RPC_TRACKER_MAGIC |
| 504 | base.sendjson(sock, [TrackerCode.STOP, self.stop_key]) |
| 505 | assert base.recvjson(sock) == TrackerCode.SUCCESS |
| 506 | sock.close() |
| 507 | |
| 508 | def terminate(self): |
| 509 | """Terminate the server process""" |
| 510 | if self.proc: |
| 511 | if self.proc.is_alive(): |
| 512 | self._stop_tracker() |
| 513 | self.proc.join(0.1) |
| 514 | if self.proc.is_alive(): |
no outgoing calls
searching dependent graphs…