| 160 | |
| 161 | @staticmethod |
| 162 | def select_and_bind(socket: zmq.Socket) -> str: |
| 163 | # randomly select a port between 1024 and 6553 |
| 164 | retry_count = 20 |
| 165 | err = None |
| 166 | while retry_count > 0: |
| 167 | try: |
| 168 | port = random.randint(1024, 65535) |
| 169 | # port = 5555 |
| 170 | url = f"tcp://localhost:{port}" |
| 171 | socket.bind(url) |
| 172 | return url |
| 173 | except zmq.error.ZMQError as e: |
| 174 | retry_count -= 1 |
| 175 | err = e |
| 176 | raise err |
| 177 | |
| 178 | # immediate switch to status, discard prev_bytes, set immediate_switch to 1 |
| 179 | def immediate_switch_to(self, status): |