summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-11-16 17:43:21 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-11-16 17:43:21 (GMT)
commit5bb1afb3322ecf370cf328d40fb95eb0a3ddab7c (patch)
tree6c9e387872b2ffb45429ee4c3e516f8b59c3b483 /Lib/asyncio
parentda32d26ab98cdb3fe27ee8d61460592fc1cae335 (diff)
downloadcpython-5bb1afb3322ecf370cf328d40fb95eb0a3ddab7c.zip
cpython-5bb1afb3322ecf370cf328d40fb95eb0a3ddab7c.tar.gz
cpython-5bb1afb3322ecf370cf328d40fb95eb0a3ddab7c.tar.bz2
asyncio: Add Transport.is_closing()
See https://github.com/python/asyncio/pull/291 for details.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_subprocess.py3
-rw-r--r--Lib/asyncio/proactor_events.py3
-rw-r--r--Lib/asyncio/selector_events.py3
-rw-r--r--Lib/asyncio/sslproto.py3
-rw-r--r--Lib/asyncio/streams.py2
-rw-r--r--Lib/asyncio/transports.py4
-rw-r--r--Lib/asyncio/unix_events.py6
7 files changed, 23 insertions, 1 deletions
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
index 6851cd2..73425d9 100644
--- a/Lib/asyncio/base_subprocess.py
+++ b/Lib/asyncio/base_subprocess.py
@@ -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
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index abe4c12..9c514c8 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -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
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 0060912..236f7b3 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -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
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 9e08b6f..dde980b 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -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.
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index 64d1020..6b5e96a 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -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
diff --git a/Lib/asyncio/transports.py b/Lib/asyncio/transports.py
index 03099e3..9a6d919 100644
--- a/Lib/asyncio/transports.py
+++ b/Lib/asyncio/transports.py
@@ -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.
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index bf3b084..f75e89f 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -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