Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5bb1afb3
Commit
5bb1afb3
authored
Nov 16, 2015
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: Add Transport.is_closing()
See
https://github.com/python/asyncio/pull/291
for details.
parent
da32d26a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
36 additions
and
14 deletions
+36
-14
Lib/asyncio/base_subprocess.py
Lib/asyncio/base_subprocess.py
+3
-0
Lib/asyncio/proactor_events.py
Lib/asyncio/proactor_events.py
+3
-0
Lib/asyncio/selector_events.py
Lib/asyncio/selector_events.py
+3
-0
Lib/asyncio/sslproto.py
Lib/asyncio/sslproto.py
+3
-0
Lib/asyncio/streams.py
Lib/asyncio/streams.py
+1
-1
Lib/asyncio/transports.py
Lib/asyncio/transports.py
+4
-0
Lib/asyncio/unix_events.py
Lib/asyncio/unix_events.py
+6
-0
Lib/test/test_asyncio/test_proactor_events.py
Lib/test/test_asyncio/test_proactor_events.py
+3
-3
Lib/test/test_asyncio/test_selector_events.py
Lib/test/test_asyncio/test_selector_events.py
+3
-3
Lib/test/test_asyncio/test_subprocess.py
Lib/test/test_asyncio/test_subprocess.py
+1
-1
Lib/test/test_asyncio/test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+6
-6
No files found.
Lib/asyncio/base_subprocess.py
View file @
5bb1afb3
...
...
@@ -87,6 +87,9 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
def
_start
(
self
,
args
,
shell
,
stdin
,
stdout
,
stderr
,
bufsize
,
**
kwargs
):
raise
NotImplementedError
def
is_closing
(
self
):
return
self
.
_closed
def
close
(
self
):
if
self
.
_closed
:
return
...
...
Lib/asyncio/proactor_events.py
View file @
5bb1afb3
...
...
@@ -65,6 +65,9 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
def
_set_extra
(
self
,
sock
):
self
.
_extra
[
'pipe'
]
=
sock
def
is_closing
(
self
):
return
self
.
_closing
def
close
(
self
):
if
self
.
_closing
:
return
...
...
Lib/asyncio/selector_events.py
View file @
5bb1afb3
...
...
@@ -556,6 +556,9 @@ class _SelectorTransport(transports._FlowControlMixin,
def
abort
(
self
):
self
.
_force_close
(
None
)
def
is_closing
(
self
):
return
self
.
_closing
def
close
(
self
):
if
self
.
_closing
:
return
...
...
Lib/asyncio/sslproto.py
View file @
5bb1afb3
...
...
@@ -304,6 +304,9 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
"""Get optional transport information."""
return
self
.
_ssl_protocol
.
_get_extra_info
(
name
,
default
)
def
is_closing
(
self
):
return
self
.
_closed
def
close
(
self
):
"""Close the transport.
...
...
Lib/asyncio/streams.py
View file @
5bb1afb3
...
...
@@ -302,7 +302,7 @@ class StreamWriter:
if
exc
is
not
None
:
raise
exc
if
self
.
_transport
is
not
None
:
if
self
.
_transport
.
_closing
:
if
self
.
_transport
.
is_closing
()
:
# Yield to the event loop so connection_lost() may be
# called. Without this, _drain_helper() would return
# immediately, and code that calls
...
...
Lib/asyncio/transports.py
View file @
5bb1afb3
...
...
@@ -19,6 +19,10 @@ class BaseTransport:
"""Get optional transport information."""
return
self
.
_extra
.
get
(
name
,
default
)
def
is_closing
(
self
):
"""Return True if the transport is closing or closed."""
raise
NotImplementedError
def
close
(
self
):
"""Close the transport.
...
...
Lib/asyncio/unix_events.py
View file @
5bb1afb3
...
...
@@ -364,6 +364,9 @@ class _UnixReadPipeTransport(transports.ReadTransport):
def
resume_reading
(
self
):
self
.
_loop
.
add_reader
(
self
.
_fileno
,
self
.
_read_ready
)
def
is_closing
(
self
):
return
self
.
_closing
def
close
(
self
):
if
not
self
.
_closing
:
self
.
_close
(
None
)
...
...
@@ -548,6 +551,9 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
self
.
_loop
.
remove_reader
(
self
.
_fileno
)
self
.
_loop
.
call_soon
(
self
.
_call_connection_lost
,
None
)
def
is_closing
(
self
):
return
self
.
_closing
def
close
(
self
):
if
self
.
_pipe
is
not
None
and
not
self
.
_closing
:
# write_eof is all what we needed to close the write pipe
...
...
Lib/test/test_asyncio/test_proactor_events.py
View file @
5bb1afb3
...
...
@@ -204,7 +204,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr
.
close
()
test_utils
.
run_briefly
(
self
.
loop
)
self
.
protocol
.
connection_lost
.
assert_called_with
(
None
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertEqual
(
tr
.
_conn_lost
,
1
)
self
.
protocol
.
connection_lost
.
reset_mock
()
...
...
@@ -298,7 +298,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
self
.
loop
,
self
.
sock
,
self
.
protocol
)
self
.
assertTrue
(
tr
.
can_write_eof
())
tr
.
write_eof
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
loop
.
_run_once
()
self
.
assertTrue
(
self
.
sock
.
close
.
called
)
tr
.
close
()
...
...
@@ -309,7 +309,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr
.
_loop
.
_proactor
.
send
.
return_value
=
f
tr
.
write
(
b'data'
)
tr
.
write_eof
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertFalse
(
self
.
sock
.
shutdown
.
called
)
tr
.
_loop
.
_proactor
.
send
.
assert_called_with
(
self
.
sock
,
b'data'
)
f
.
set_result
(
4
)
...
...
Lib/test/test_asyncio/test_selector_events.py
View file @
5bb1afb3
...
...
@@ -698,7 +698,7 @@ class SelectorTransportTests(test_utils.TestCase):
tr
=
self
.
create_transport
()
tr
.
close
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertEqual
(
1
,
self
.
loop
.
remove_reader_count
[
7
])
self
.
protocol
.
connection_lost
(
None
)
self
.
assertEqual
(
tr
.
_conn_lost
,
1
)
...
...
@@ -723,7 +723,7 @@ class SelectorTransportTests(test_utils.TestCase):
self
.
loop
.
add_writer
(
7
,
mock
.
sentinel
)
tr
.
_force_close
(
None
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertEqual
(
tr
.
_buffer
,
list_to_buffer
())
self
.
assertFalse
(
self
.
loop
.
readers
)
self
.
assertFalse
(
self
.
loop
.
writers
)
...
...
@@ -1436,7 +1436,7 @@ class SelectorSslTransportTests(test_utils.TestCase):
tr
=
self
.
_make_one
()
tr
.
close
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertEqual
(
1
,
self
.
loop
.
remove_reader_count
[
1
])
self
.
assertEqual
(
tr
.
_conn_lost
,
1
)
...
...
Lib/test/test_asyncio/test_subprocess.py
View file @
5bb1afb3
...
...
@@ -61,7 +61,7 @@ class SubprocessTransportTests(test_utils.TestCase):
self
.
assertTrue
(
protocol
.
connection_lost
.
called
)
self
.
assertEqual
(
protocol
.
connection_lost
.
call_args
[
0
],
(
None
,))
self
.
assertFalse
(
transport
.
_closed
)
self
.
assertFalse
(
transport
.
is_closing
()
)
self
.
assertIsNone
(
transport
.
_loop
)
self
.
assertIsNone
(
transport
.
_proc
)
self
.
assertIsNone
(
transport
.
_protocol
)
...
...
Lib/test/test_asyncio/test_unix_events.py
View file @
5bb1afb3
...
...
@@ -440,7 +440,7 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
tr
=
self
.
read_pipe_transport
()
err
=
object
()
tr
.
_close
(
err
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertFalse
(
self
.
loop
.
readers
)
test_utils
.
run_briefly
(
self
.
loop
)
self
.
protocol
.
connection_lost
.
assert_called_with
(
err
)
...
...
@@ -598,7 +598,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
tr
.
_read_ready
()
self
.
assertFalse
(
self
.
loop
.
readers
)
self
.
assertFalse
(
self
.
loop
.
writers
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
test_utils
.
run_briefly
(
self
.
loop
)
self
.
protocol
.
connection_lost
.
assert_called_with
(
None
)
...
...
@@ -658,7 +658,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self
.
assertFalse
(
self
.
loop
.
writers
)
self
.
assertFalse
(
self
.
loop
.
readers
)
self
.
assertEqual
([],
tr
.
_buffer
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
m_logexc
.
assert_called_with
(
test_utils
.
MockPattern
(
'Fatal write error on pipe transport'
...
...
@@ -694,7 +694,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self
.
assertFalse
(
self
.
loop
.
readers
)
self
.
assertFalse
(
self
.
loop
.
writers
)
self
.
assertEqual
([],
tr
.
_buffer
)
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
test_utils
.
run_briefly
(
self
.
loop
)
self
.
protocol
.
connection_lost
.
assert_called_with
(
None
)
...
...
@@ -743,7 +743,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
def
test_write_eof
(
self
):
tr
=
self
.
write_pipe_transport
()
tr
.
write_eof
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertFalse
(
self
.
loop
.
readers
)
test_utils
.
run_briefly
(
self
.
loop
)
self
.
protocol
.
connection_lost
.
assert_called_with
(
None
)
...
...
@@ -752,7 +752,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
tr
=
self
.
write_pipe_transport
()
tr
.
_buffer
=
[
b'data'
]
tr
.
write_eof
()
self
.
assertTrue
(
tr
.
_closing
)
self
.
assertTrue
(
tr
.
is_closing
()
)
self
.
assertFalse
(
self
.
protocol
.
connection_lost
.
called
)
...
...
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