Skip to content

Commit c4cab43

Browse files
committed
Revert "fix find port func"
This reverts commit eac2951.
1 parent eac2951 commit c4cab43

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/idom/server/utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import asyncio
2-
import errno
3-
import socket
42
import time
53
from contextlib import closing
64
from functools import wraps
75
from importlib import import_module
6+
from socket import socket
87
from threading import Event, Thread
98
from typing import Any, Callable, List, Optional, TypeVar, cast
109

@@ -87,15 +86,13 @@ def find_builtin_server_type(type_name: str) -> ServerFactory[Any, Any]:
8786
def find_available_port(host: str, port_min: int = 8000, port_max: int = 9000) -> int:
8887
"""Get a port that's available for the given host and port range"""
8988
for port in range(port_min, port_max):
90-
with closing(socket.socket()) as sock:
91-
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
89+
with closing(socket()) as sock:
9290
try:
9391
sock.bind((host, port))
94-
except socket.error as error:
95-
if error.errno != errno.EADDRINUSE:
96-
raise
92+
except OSError:
93+
pass
9794
else:
9895
return port
9996
raise RuntimeError(
100-
f"Host {host!r} has no available port in range {port_min}-{port_max}"
97+
f"Host {host!r} has no available port in range {port_max}-{port_max}"
10198
)

0 commit comments

Comments
 (0)