mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32356: idempotent pause_/resume_reading; new is_reading method. (#4914)
This commit is contained in:
parent
2d8f06382e
commit
d757aaf9dd
9 changed files with 87 additions and 24 deletions
|
@ -152,21 +152,20 @@ class _ProactorReadPipeTransport(_ProactorBasePipeTransport,
|
|||
self._paused = False
|
||||
self._loop.call_soon(self._loop_reading)
|
||||
|
||||
def is_reading(self):
|
||||
return not self._paused and not self._closing
|
||||
|
||||
def pause_reading(self):
|
||||
if self._closing:
|
||||
raise RuntimeError('Cannot pause_reading() when closing')
|
||||
if self._paused:
|
||||
raise RuntimeError('Already paused')
|
||||
if self._closing or self._paused:
|
||||
return
|
||||
self._paused = True
|
||||
if self._loop.get_debug():
|
||||
logger.debug("%r pauses reading", self)
|
||||
|
||||
def resume_reading(self):
|
||||
if not self._paused:
|
||||
raise RuntimeError('Not paused')
|
||||
self._paused = False
|
||||
if self._closing:
|
||||
if self._closing or not self._paused:
|
||||
return
|
||||
self._paused = False
|
||||
self._loop.call_soon(self._loop_reading, self._read_fut)
|
||||
if self._loop.get_debug():
|
||||
logger.debug("%r resumes reading", self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue