Use the socket module to find an open port. Returns ------- int An open port
()
| 95 | |
| 96 | |
| 97 | def find_open_port(): |
| 98 | """ |
| 99 | Use the socket module to find an open port. |
| 100 | |
| 101 | Returns |
| 102 | ------- |
| 103 | int |
| 104 | An open port |
| 105 | """ |
| 106 | s = socket.socket() |
| 107 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 108 | s.bind(("", 0)) |
| 109 | _, port = s.getsockname() |
| 110 | s.close() |
| 111 | |
| 112 | return port |
| 113 | |
| 114 | |
| 115 | def retry(min_wait=5, max_wait=10, max_delay=60000): |
no test coverage detected