Tries to connect to the server at port to see if it is running. Args: port: port number host: hostname or IP
(port: int, host: str | None = "localhost")
| 110 | |
| 111 | |
| 112 | def is_connectable(port: int, host: str | None = "localhost") -> bool: |
| 113 | """Tries to connect to the server at port to see if it is running. |
| 114 | |
| 115 | Args: |
| 116 | port: port number |
| 117 | host: hostname or IP |
| 118 | """ |
| 119 | socket_ = None |
| 120 | try: |
| 121 | socket_ = socket.create_connection((host, port), 1) |
| 122 | result = True |
| 123 | except _is_connectable_exceptions: |
| 124 | result = False |
| 125 | finally: |
| 126 | if socket_: |
| 127 | try: |
| 128 | socket_.shutdown(socket.SHUT_RDWR) |
| 129 | except Exception: |
| 130 | pass |
| 131 | socket_.close() |
| 132 | return result |
| 133 | |
| 134 | |
| 135 | def is_url_connectable( |
no test coverage detected