Skip to content
30 changes: 24 additions & 6 deletions Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,32 @@ def close(self):
self._selector.close()
self._selector = None

def _close_self_pipe(self):
self._remove_reader(self._ssock.fileno())
self._ssock.close()
self._ssock = None
self._csock.close()
self._csock = None
def _close_self_pipe(self, shutdown=False):
if self._ssock is not None:
self._remove_reader(self._ssock.fileno())
if shutdown:
try:
self._ssock.shutdown(socket.SHUT_RDWR)
except OSError as e:
# Log the error with more context
print(f"Error shutting down _ssock (fileno={self._ssock.fileno()}): {e}")
self._ssock.close()
self._ssock = None

if self._csock is not None:
if shutdown:
try:
self._csock.shutdown(socket.SHUT_RDWR)
except OSError as e:
# Log the error with more context
print(f"Error shutting down _csock (fileno={self._csock.fileno()}): {e}")
self._csock.close()
self._csock = None

self._internal_fds -= 1



def _make_self_pipe(self):
# A self-socket, really. :-)
self._ssock, self._csock = socket.socketpair()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Issue: :gh:`130850`

Detailed changes: Modified _close_self_pipe function in selector_events.py in python/asyncio. This update introduces a shutdown parameter, allowing for either a socket shutdown or the default socket close
Loading