summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/unix_events.py
diff options
context:
space:
mode:
authorItayazolay <itayazolay@gmail.com>2023-04-27 10:03:29 (GMT)
committerGitHub <noreply@github.com>2023-04-27 10:03:29 (GMT)
commit78942ecd9b1dbbd95e99cc298b0154fe126dac12 (patch)
tree1f273bbaefcf0b51c4b714292925e2f963220871 /Lib/asyncio/unix_events.py
parentdff8e5dc8d0758d1f9c55fdef308e44aefebe1a2 (diff)
downloadcpython-78942ecd9b1dbbd95e99cc298b0154fe126dac12.zip
cpython-78942ecd9b1dbbd95e99cc298b0154fe126dac12.tar.gz
cpython-78942ecd9b1dbbd95e99cc298b0154fe126dac12.tar.bz2
gh-103607: Fix `pause_reading` to work when called from `connection_made` in `asyncio`. (#17425)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/asyncio/unix_events.py')
-rw-r--r--Lib/asyncio/unix_events.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index b21e039..17fb4d5 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -485,13 +485,21 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
- self._loop.call_soon(self._loop._add_reader,
+ self._loop.call_soon(self._add_reader,
self._fileno, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self._loop.call_soon(futures._set_result_unless_cancelled,
waiter, None)
+ def _add_reader(self, fd, callback):
+ if not self.is_reading():
+ return
+ self._loop._add_reader(fd, callback)
+
+ def is_reading(self):
+ return not self._paused and not self._closing
+
def __repr__(self):
info = [self.__class__.__name__]
if self._pipe is None:
@@ -532,7 +540,7 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self._loop.call_soon(self._call_connection_lost, None)
def pause_reading(self):
- if self._closing or self._paused:
+ if not self.is_reading():
return
self._paused = True
self._loop._remove_reader(self._fileno)