MCPcopy Index your code
hub / github.com/python/cpython / create_task

Method create_task

Lib/asyncio/taskgroups.py:182–211  ·  view source on GitHub ↗

Create a new task in this group and return it. Similar to `asyncio.create_task`.

(self, coro, **kwargs)

Source from the content-addressed store, hash-verified

180
181
182 def create_task(self, coro, **kwargs):
183 """Create a new task in this group and return it.
184
185 Similar to `asyncio.create_task`.
186 """
187 if not self._entered:
188 coro.close()
189 raise RuntimeError(f"TaskGroup {self!r} has not been entered")
190 if self._exiting and not self._tasks:
191 coro.close()
192 raise RuntimeError(f"TaskGroup {self!r} is finished")
193 if self._aborting:
194 coro.close()
195 raise RuntimeError(f"TaskGroup {self!r} is shutting down")
196 task = self._loop.create_task(coro, **kwargs)
197
198 futures.future_add_to_awaited_by(task, self._parent_task)
199
200 # Always schedule the done callback even if the task is
201 # already done (e.g. if the coro was able to complete eagerly),
202 # otherwise if the task completes with an exception then it will cancel
203 # the current task too early. gh-128550, gh-128588
204 self._tasks.add(task)
205 task.add_done_callback(self._on_task_done)
206 try:
207 return task
208 finally:
209 # gh-128552: prevent a refcycle of
210 # task.exception().__traceback__->TaskGroup.create_task->task
211 del task
212
213 # Since Python 3.8 Tasks propagate all exceptions correctly,
214 # except for KeyboardInterrupt and SystemExit which are

Callers 14

run_testbedFunction · 0.45
_accept_connectionMethod · 0.45
callbackMethod · 0.45
__init__Method · 0.45
create_taskFunction · 0.45
ensure_futureFunction · 0.45
runMethod · 0.45
run_one_coroFunction · 0.45
staggered_raceFunction · 0.45

Calls 3

closeMethod · 0.45
addMethod · 0.45
add_done_callbackMethod · 0.45