mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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
This commit is contained in:
parent
e10920f0d1
commit
2dba23af71
4 changed files with 23 additions and 7 deletions
|
@ -111,12 +111,14 @@ class CoroWrapper:
|
||||||
frame = getattr(gen, 'gi_frame', None)
|
frame = getattr(gen, 'gi_frame', None)
|
||||||
if frame is not None and frame.f_lasti == -1:
|
if frame is not None and frame.f_lasti == -1:
|
||||||
func = events._format_callback(self.func, ())
|
func = events._format_callback(self.func, ())
|
||||||
tb = ''.join(traceback.format_list(self._source_traceback))
|
msg = 'Coroutine %s was never yielded from' % func
|
||||||
message = ('Coroutine %s was never yielded from\n'
|
tb = getattr(self, '_source_traceback', ())
|
||||||
'Coroutine object created at (most recent call last):\n'
|
if tb:
|
||||||
'%s'
|
tb = ''.join(traceback.format_list(tb))
|
||||||
% (func, tb.rstrip()))
|
msg += ('\nCoroutine object created at '
|
||||||
logger.error(message)
|
'(most recent call last):\n')
|
||||||
|
msg += tb.rstrip()
|
||||||
|
logger.error(msg)
|
||||||
|
|
||||||
|
|
||||||
def coroutine(func):
|
def coroutine(func):
|
||||||
|
|
|
@ -109,6 +109,9 @@ class Task(futures.Future):
|
||||||
if self._callbacks:
|
if self._callbacks:
|
||||||
info.append(self._format_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))
|
return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
|
||||||
|
|
||||||
def get_stack(self, *, limit=None):
|
def get_stack(self, *, limit=None):
|
||||||
|
|
|
@ -494,7 +494,7 @@ class _UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
||||||
universal_newlines=False, bufsize=bufsize, **kwargs)
|
universal_newlines=False, bufsize=bufsize, **kwargs)
|
||||||
if stdin_w is not None:
|
if stdin_w is not None:
|
||||||
stdin.close()
|
stdin.close()
|
||||||
self._proc.stdin = open(stdin_w.detach(), 'rb', buffering=bufsize)
|
self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize)
|
||||||
|
|
||||||
|
|
||||||
class AbstractChildWatcher:
|
class AbstractChildWatcher:
|
||||||
|
|
|
@ -218,6 +218,17 @@ class TaskTests(test_utils.TestCase):
|
||||||
'<Task pending %s cb=[<Dummy>()]>' % coro)
|
'<Task pending %s cb=[<Dummy>()]>' % coro)
|
||||||
self.loop.run_until_complete(t)
|
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):
|
def test_task_basics(self):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def outer():
|
def outer():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue