Commit 2b69506c authored by Victor Stinner's avatar Victor Stinner

Issue #10816: multiprocessing.SocketClient() closes the socket on error

Use a context manager to close immediatly the socket on error.
parent 90efac7f
...@@ -281,7 +281,7 @@ def SocketClient(address): ...@@ -281,7 +281,7 @@ def SocketClient(address):
Return a connection object connected to the socket given by `address` Return a connection object connected to the socket given by `address`
''' '''
family = address_type(address) family = address_type(address)
s = socket.socket( getattr(socket, family) ) with socket.socket( getattr(socket, family) ) as s:
t = _init_timeout() t = _init_timeout()
while 1: while 1:
...@@ -299,7 +299,6 @@ def SocketClient(address): ...@@ -299,7 +299,6 @@ def SocketClient(address):
fd = duplicate(s.fileno()) fd = duplicate(s.fileno())
conn = _multiprocessing.Connection(fd) conn = _multiprocessing.Connection(fd)
s.close()
return conn return conn
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment