Skip to content

Commit 576ef47

Browse files
authored
Update selector_events.py for gh-130850
1 parent d8a1cf4 commit 576ef47

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Lib/asyncio/selector_events.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,32 @@ def close(self):
109109

110110
def _close_self_pipe(self):
111111
self._remove_reader(self._ssock.fileno())
112-
self._ssock.close()
113-
self._ssock = None
114-
self._csock.close()
115-
self._csock = None
116-
self._internal_fds -= 1
112+
113+
# Handle shutdown and close for _ssock
114+
if self._ssock:
115+
try:
116+
self._ssock.shutdown(socket.SHUT_RDWR)
117+
except OSError as e:
118+
# Log the error or handle it as necessary
119+
print(f"Error shutting down _ssock: {e}")
120+
finally:
121+
self._ssock.close()
122+
self._ssock = None
123+
124+
# Handle shutdown and close for _csock
125+
if self._csock:
126+
try:
127+
self._csock.shutdown(socket.SHUT_RDWR)
128+
except OSError as e:
129+
# Log the error or handle it as necessary
130+
print(f"Error shutting down _csock: {e}")
131+
finally:
132+
self._csock.close()
133+
self._csock = None
134+
135+
self._internal_fds -= 1
136+
137+
117138

118139
def _make_self_pipe(self):
119140
# A self-socket, really. :-)

0 commit comments

Comments
 (0)