8000 Add asyncio.run() and asyncio.run_forever() functions. by 1st1 · Pull Request #465 · python/asyncio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Add asyncio.run() and asyncio.run_forever() functions. #465

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rollback all changes to tasks.py; drop forever
  • Loading branch information
1st1 committed Nov 15, 2016
commit fa721ee80e17bcbdde8f5f5431538300436b2301
2 changes: 1 addition & 1 deletion asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
subprocess.__all__ +
tasks.__all__ +
transports.__all__ +
['run', 'forever']) # Will fix this later.
['run']) # Will fix this later.

if sys.platform == 'win32': # pragma: no cover
from .windows_events import *
Expand Down
29 changes: 1 addition & 28 deletions asyncio/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""asyncio.run() function."""

__all__ = ['run', 'forever']
__all__ = ['run']

import inspect
import threading
Expand All @@ -15,33 +15,6 @@ def _isasyncgen(obj):
return False


@coroutines.coroutine
def forever():
"""Wait until the current event loop stops running.

The coroutine will return None if the loop is stopped by
calling the `loop.stop()` method.

The coroutine will propagate any exception that caused
the loop to stop;

It is recommended to use this coroutine with the asyncio.run()
function:

async def coro():
print('hi')
try:
await asyncio.forever()
except KeyboardInterrupt:
await asyncio.sleep(1)
print('bye')

asyncio.run(coro())
"""
loop = events.get_event_loop()
return (yield from loop.get_forever_future())


def run(coro, *, debug=False):
"""Run a coroutine.

Expand Down
2 changes: 1 addition & 1 deletion asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _step(self, exc=None):
def _wakeup(self, future):
try:
future.result()
except BaseException as exc:
except Exception as exc:
# This may also be a cancellation.
self._step(exc)
else:
Expand Down
0