Skip to content

Commit 74a7808

Browse files
committed
[py] Close socket
1 parent 592684d commit 74a7808

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

py/selenium/webdriver/remote/server.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ def start(self):
117117
if self.host is not None:
118118
command.extend(["--host", self.host])
119119

120-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
121120
host = self.host if self.host is not None else "localhost"
121+
122122
try:
123-
sock.connect((host, self.port))
123+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
124+
sock.connect((host, self.port))
124125
raise ConnectionError(f"Selenium server is already running, or something else is using port {self.port}")
125126
except ConnectionRefusedError:
126127
print(f"Starting Selenium server at: {self.path}")

0 commit comments

Comments
 (0)