Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d757aaf9
Unverified
Kaydet (Commit)
d757aaf9
authored
Ara 18, 2017
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
Ara 18, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32356: idempotent pause_/resume_reading; new is_reading method. (#4914)
üst
2d8f0638
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
87 additions
and
24 deletions
+87
-24
asyncio-protocol.rst
Doc/library/asyncio-protocol.rst
+14
-0
proactor_events.py
Lib/asyncio/proactor_events.py
+7
-8
selector_events.py
Lib/asyncio/selector_events.py
+7
-8
sslproto.py
Lib/asyncio/sslproto.py
+6
-0
transports.py
Lib/asyncio/transports.py
+4
-0
test_proactor_events.py
Lib/test/test_asyncio/test_proactor_events.py
+10
-0
test_selector_events.py
Lib/test/test_asyncio/test_selector_events.py
+25
-3
utils.py
Lib/test/test_asyncio/utils.py
+12
-5
2017-12-17-22-50-51.bpo-32356.roZJpA.rst
...S.d/next/Library/2017-12-17-22-50-51.bpo-32356.roZJpA.rst
+2
-0
No files found.
Doc/library/asyncio-protocol.rst
Dosyayı görüntüle @
d757aaf9
...
...
@@ -118,17 +118,31 @@ ReadTransport
Interface for read-only transports.
.. method:: is_reading()
Return ``True`` if the transport is receiving new data.
.. versionadded:: 3.7
.. method:: pause_reading()
Pause the receiving end of the transport. No data will be passed to
the protocol's :meth:`data_received` method until :meth:`resume_reading`
is called.
.. versionchanged:: 3.7
The method is idempotent, i.e. it can be called when the
transport is already paused or closed.
.. method:: resume_reading()
Resume the receiving end. The protocol's :meth:`data_received` method
will be called once again if some data is available for reading.
.. versionchanged:: 3.7
The method is idempotent, i.e. it can be called when the
transport is already reading.
WriteTransport
--------------
...
...
Lib/asyncio/proactor_events.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -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
)
...
...
Lib/asyncio/selector_events.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -702,22 +702,21 @@ class _SelectorSocketTransport(_SelectorTransport):
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
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
self
.
_loop
.
_remove_reader
(
self
.
_sock_fd
)
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
.
_add_reader
(
self
.
_sock_fd
,
self
.
_read_ready
)
if
self
.
_loop
.
get_debug
():
logger
.
debug
(
"
%
r resumes reading"
,
self
)
...
...
Lib/asyncio/sslproto.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -317,6 +317,12 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
source
=
self
)
self
.
close
()
def
is_reading
(
self
):
tr
=
self
.
_ssl_protocol
.
_transport
if
tr
is
None
:
raise
RuntimeError
(
'SSL transport has not been initialized yet'
)
return
tr
.
is_reading
()
def
pause_reading
(
self
):
"""Pause the receiving end.
...
...
Lib/asyncio/transports.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -44,6 +44,10 @@ class BaseTransport:
class
ReadTransport
(
BaseTransport
):
"""Interface for read-only transports."""
def
is_reading
(
self
):
"""Return True if the transport is receiving."""
raise
NotImplementedError
def
pause_reading
(
self
):
"""Pause the receiving end.
...
...
Lib/test/test_asyncio/test_proactor_events.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -334,26 +334,36 @@ class ProactorSocketTransportTests(test_utils.TestCase):
f
=
asyncio
.
Future
(
loop
=
self
.
loop
)
f
.
set_result
(
msg
)
futures
.
append
(
f
)
self
.
loop
.
_proactor
.
recv
.
side_effect
=
futures
self
.
loop
.
_run_once
()
self
.
assertFalse
(
tr
.
_paused
)
self
.
assertTrue
(
tr
.
is_reading
())
self
.
loop
.
_run_once
()
self
.
protocol
.
data_received
.
assert_called_with
(
b
'data1'
)
self
.
loop
.
_run_once
()
self
.
protocol
.
data_received
.
assert_called_with
(
b
'data2'
)
tr
.
pause_reading
()
tr
.
pause_reading
()
self
.
assertTrue
(
tr
.
_paused
)
self
.
assertFalse
(
tr
.
is_reading
())
for
i
in
range
(
10
):
self
.
loop
.
_run_once
()
self
.
protocol
.
data_received
.
assert_called_with
(
b
'data2'
)
tr
.
resume_reading
()
tr
.
resume_reading
()
self
.
assertFalse
(
tr
.
_paused
)
self
.
assertTrue
(
tr
.
is_reading
())
self
.
loop
.
_run_once
()
self
.
protocol
.
data_received
.
assert_called_with
(
b
'data3'
)
self
.
loop
.
_run_once
()
self
.
protocol
.
data_received
.
assert_called_with
(
b
'data4'
)
tr
.
close
()
self
.
assertFalse
(
tr
.
is_reading
())
def
pause_writing_transport
(
self
,
high
):
tr
=
self
.
socket_transport
()
...
...
Lib/test/test_asyncio/test_selector_events.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -80,10 +80,23 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
with
test_utils
.
disable_logger
():
transport
=
self
.
loop
.
_make_ssl_transport
(
m
,
asyncio
.
Protocol
(),
m
,
waiter
)
with
self
.
assertRaisesRegex
(
RuntimeError
,
r'SSL transport.*not.*initialized'
):
transport
.
is_reading
()
# execute the handshake while the logger is disabled
# to ignore SSL handshake failure
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertTrue
(
transport
.
is_reading
())
transport
.
pause_reading
()
transport
.
pause_reading
()
self
.
assertFalse
(
transport
.
is_reading
())
transport
.
resume_reading
()
transport
.
resume_reading
()
self
.
assertTrue
(
transport
.
is_reading
())
# Sanity check
class_name
=
transport
.
__class__
.
__name__
self
.
assertIn
(
"ssl"
,
class_name
.
lower
())
...
...
@@ -894,15 +907,24 @@ class SelectorSocketTransportTests(test_utils.TestCase):
tr
=
self
.
socket_transport
()
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertFalse
(
tr
.
_paused
)
self
.
assertTrue
(
tr
.
is_reading
())
self
.
loop
.
assert_reader
(
7
,
tr
.
_read_ready
)
tr
.
pause_reading
()
tr
.
pause_reading
()
self
.
assertTrue
(
tr
.
_paused
)
self
.
assertFalse
(
7
in
self
.
loop
.
readers
)
self
.
assertFalse
(
tr
.
is_reading
())
self
.
loop
.
assert_no_reader
(
7
)
tr
.
resume_reading
()
tr
.
resume_reading
()
self
.
assertFalse
(
tr
.
_paused
)
self
.
assertTrue
(
tr
.
is_reading
())
self
.
loop
.
assert_reader
(
7
,
tr
.
_read_ready
)
with
self
.
assertRaises
(
RuntimeError
):
tr
.
resume_reading
()
tr
.
close
()
self
.
assertFalse
(
tr
.
is_reading
())
self
.
loop
.
assert_no_reader
(
7
)
def
test_read_ready
(
self
):
transport
=
self
.
socket_transport
()
...
...
Lib/test/test_asyncio/utils.py
Dosyayı görüntüle @
d757aaf9
...
...
@@ -327,12 +327,19 @@ class TestLoop(base_events.BaseEventLoop):
return
False
def
assert_reader
(
self
,
fd
,
callback
,
*
args
):
assert
fd
in
self
.
readers
,
'fd {} is not registered'
.
format
(
fd
)
if
fd
not
in
self
.
readers
:
raise
AssertionError
(
f
'fd {fd} is not registered'
)
handle
=
self
.
readers
[
fd
]
assert
handle
.
_callback
==
callback
,
'{!r} != {!r}'
.
format
(
handle
.
_callback
,
callback
)
assert
handle
.
_args
==
args
,
'{!r} != {!r}'
.
format
(
handle
.
_args
,
args
)
if
handle
.
_callback
!=
callback
:
raise
AssertionError
(
f
'unexpected callback: {handle._callback} != {callback}'
)
if
handle
.
_args
!=
args
:
raise
AssertionError
(
f
'unexpected callback args: {handle._args} != {args}'
)
def
assert_no_reader
(
self
,
fd
):
if
fd
in
self
.
readers
:
raise
AssertionError
(
f
'fd {fd} is registered'
)
def
_add_writer
(
self
,
fd
,
callback
,
*
args
):
self
.
writers
[
fd
]
=
events
.
Handle
(
callback
,
args
,
self
)
...
...
Misc/NEWS.d/next/Library/2017-12-17-22-50-51.bpo-32356.roZJpA.rst
0 → 100644
Dosyayı görüntüle @
d757aaf9
asyncio.transport.resume_reading() and pause_reading() are now idempotent.
New transport.is_reading() method is added.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment