Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import tasks


def run(main, *, debug=False):
def run(main, *, debug=False, exception_handler=None):
"""Execute the coroutine and return the result.

This function runs the passed coroutine, taking care of
Expand All @@ -17,6 +17,8 @@ def run(main, *, debug=False):

If debug is True, the event loop will be run in debug mode.

You can provide custom event loop exception handler with exception_handler.

This function always creates a new event loop and closes it at the end.
It should be used as a main entry point for asyncio programs, and should
ideally only be called once.
Expand All @@ -40,6 +42,8 @@ async def main():
try:
events.set_event_loop(loop)
loop.set_debug(debug)
if exception_handler:
loop.set_exception_handler(exception_handler)
return loop.run_until_complete(main)
finally:
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow to provide custom exception handler to `asyncio.run()`