8000 GH-97696: Initial work on eager tasks by gvanrossum · Pull Request #98137 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-97696: Initial work on eager tasks #98137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
Make it work with _CTask.
  • Loading branch information
gvanrossum committed Oct 10, 2022
commit 857312cf9742780a9739da1707fada0b73adecbc
32 changes: 17 additions & 15 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,24 +458,26 @@ def eager_task_factory(self, coro, *, name=None, context=None):
Otherwise schedule the resumption and return a task.
"""
self._check_closed()
try:
yield_result = coro.send(None)
except BaseException as exc:
fut = self.create_future()
# XXX What about AsyncStopIteration?
if isinstance(exc, StopIteration):
fut.set_result(exc.value)
else:
fut.set_exception(exc)
return fut
# Do not go through the task factory.
# This _is_ the task factory.
if tasks.Task is not tasks._PyTask:
task = tasks.Task(coro, loop=self, name=name, context=context)
else:
# Do not go through the task factory.
# This _is_ the task factory.
try:
yield_result = coro.send(None)
except BaseException as exc:
fut = self.create_future()
# XXX What about AsyncStopIteration?
if isinstance(exc, StopIteration):
fut.set_result(exc.value)
else:
fut.set_exception(exc)
return fut
task = tasks.Task(coro, loop=self, name=name, context=context,
yield_result=yield_result)
if task._source_traceback:
del task._source_traceback[-1]
return task
if task._source_traceback:
del task._source_traceback[-1]
return task

def set_task_factory(self, factory):
"""Set a task factory that will be used by loop.create_task().
Expand Down
0