[Python-checkins] cpython (3.4): asyncio: sync with Tulip

victor.stinner python-checkins at python.org
Thu Jul 3 01:00:30 CEST 2014


http://hg.python.org/cpython/rev/4b612f7bffd4
changeset:   91528:4b612f7bffd4
branch:      3.4
parent:      91525:652b62213072
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jul 03 00:59:00 2014 +0200
summary:
  asyncio: sync with Tulip

* _UnixSubprocessTransport: fix file mode of stdin. Open stdin in write mode,
  not in read mode
* Examples: close the event loop at exit
* More reliable CoroWrapper.__del__. If the constructor is interrupted by
  KeyboardInterrupt or the coroutine objet is destroyed lately, some the
  _source_traceback attribute doesn't exist anymore.
* repr(Task): include also the future the task is waiting for

files:
  Lib/asyncio/coroutines.py           |  14 ++++++++------
  Lib/asyncio/tasks.py                |   3 +++
  Lib/asyncio/unix_events.py          |   2 +-
  Lib/test/test_asyncio/test_tasks.py |  11 +++++++++++
  4 files changed, 23 insertions(+), 7 deletions(-)


diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -111,12 +111,14 @@
         frame = getattr(gen, 'gi_frame', None)
         if frame is not None and frame.f_lasti == -1:
             func = events._format_callback(self.func, ())
-            tb = ''.join(traceback.format_list(self._source_traceback))
-            message = ('Coroutine %s was never yielded from\n'
-                       'Coroutine object created at (most recent call last):\n'
-                       '%s'
-                       % (func, tb.rstrip()))
-            logger.error(message)
+            msg = 'Coroutine %s was never yielded from' % func
+            tb = getattr(self, '_source_traceback', ())
+            if tb:
+                tb = ''.join(traceback.format_list(tb))
+                msg += ('\nCoroutine object created at '
+                        '(most recent call last):\n')
+                msg += tb.rstrip()
+            logger.error(msg)
 
 
 def coroutine(func):
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -109,6 +109,9 @@
         if self._callbacks:
             info.append(self._format_callbacks())
 
+        if self._fut_waiter is not None:
+            info.append('wait_for=%r' % self._fut_waiter)
+
         return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
 
     def get_stack(self, *, limit=None):
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -494,7 +494,7 @@
             universal_newlines=False, bufsize=bufsize, **kwargs)
         if stdin_w is not None:
             stdin.close()
-            self._proc.stdin = open(stdin_w.detach(), 'rb', buffering=bufsize)
+            self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize)
 
 
 class AbstractChildWatcher:
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -218,6 +218,17 @@
                          '<Task pending %s cb=[<Dummy>()]>' % coro)
         self.loop.run_until_complete(t)
 
+    def test_task_repr_wait_for(self):
+        @asyncio.coroutine
+        def wait_for(fut):
+            return (yield from fut)
+
+        fut = asyncio.Future(loop=self.loop)
+        task = asyncio.Task(wait_for(fut), loop=self.loop)
+        test_utils.run_briefly(self.loop)
+        self.assertRegex(repr(task),
+                         '<Task .* wait_for=%s>' % re.escape(repr(fut)))
+
     def test_task_basics(self):
         @asyncio.coroutine
         def outer():

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list