diff -r 24282c6f6019 Lib/asyncio/base_events.py --- a/Lib/asyncio/base_events.py Wed Jun 25 23:59:31 2014 +0200 +++ b/Lib/asyncio/base_events.py Thu Jun 26 00:03:06 2014 +0200 @@ -224,7 +224,12 @@ class BaseEventLoop(events.AbstractEvent Return the Future's result, or raise its exception. """ self._check_closed() + + new_task = not isinstance(future, futures.Future) future = tasks.async(future, loop=self) + if new_task: + future._warn_pending = False + future.add_done_callback(_raise_stop_error) self.run_forever() future.remove_done_callback(_raise_stop_error) diff -r 24282c6f6019 Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py Wed Jun 25 23:59:31 2014 +0200 +++ b/Lib/asyncio/tasks.py Thu Jun 26 00:03:06 2014 +0200 @@ -197,13 +197,14 @@ class Task(futures.Future): self._must_cancel = False self._loop.call_soon(self._step) self.__class__._all_tasks.add(self) + self._warn_pending = True # On Python 3.3 or older, objects with a destructor part of a reference # cycle are never destroyed. It's not more the case on Python 3.4 thanks to # the PEP 442. if _PY34: def __del__(self): - if self._state == futures._PENDING: + if self._state == futures._PENDING and self._warn_pending: self._loop.call_exception_handler({ 'task': self, 'message': 'Task was destroyed but it is pending!', @@ -444,7 +445,15 @@ def wait(fs, *, loop=None, timeout=None, if loop is None: loop = events.get_event_loop() - fs = {async(f, loop=loop) for f in set(fs)} + new_fs = [] + for fut in set(fs): + if isinstance(fut, futures.Future): + task = fut + else: + task = async(fut, loop=loop) + task._warn_pending = False + new_fs.append(task) + fs = new_fs if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED): raise ValueError('Invalid return_when value: {}'.format(return_when)) @@ -662,7 +671,15 @@ def gather(*coros_or_futures, loop=None, prevent the cancellation of one child to cause other children to be cancelled.) """ - arg_to_fut = {arg: async(arg, loop=loop) for arg in set(coros_or_futures)} + arg_to_fut = {} + for arg in set(coros_or_futures): + if isinstance(arg, futures.Future): + fut = arg + else: + fut = async(arg, loop=loop) + fut._warn_pending = False + arg_to_fut[arg] = fut + children = [arg_to_fut[arg] for arg in coros_or_futures] n = len(children) if n == 0: diff -r 24282c6f6019 Lib/asyncio/test_utils.py --- a/Lib/asyncio/test_utils.py Wed Jun 25 23:59:31 2014 +0200 +++ b/Lib/asyncio/test_utils.py Thu Jun 26 00:03:06 2014 +0200 @@ -52,6 +52,7 @@ def run_briefly(loop): loop.run_until_complete(t) finally: gen.close() + t._warn_pending = False def run_until(loop, pred, timeout=30):