MCPcopy
hub / github.com/python-trio/trio / start_soon

Method start_soon

src/trio/_core/_run.py:1349–1394  ·  view source on GitHub ↗

Creates a child task, scheduling ``await async_fn(*args)``. If you want to run a function and immediately wait for its result, then you don't need a nursery; just use ``await async_fn(*args)``. If you want to wait for the task to initialize itself before continuing,

(
        self,
        async_fn: Callable[[Unpack[PosArgT]], Awaitable[object]],
        *args: Unpack[PosArgT],
        name: object = None,
    )

Source from the content-addressed store, hash-verified

1347 return None
1348
1349 def start_soon(
1350 self,
1351 async_fn: Callable[[Unpack[PosArgT]], Awaitable[object]],
1352 *args: Unpack[PosArgT],
1353 name: object = None,
1354 ) -> None:
1355 """Creates a child task, scheduling ``await async_fn(*args)``.
1356
1357 If you want to run a function and immediately wait for its result,
1358 then you don't need a nursery; just use ``await async_fn(*args)``.
1359 If you want to wait for the task to initialize itself before
1360 continuing, see :meth:`start`, the other fundamental method for
1361 creating concurrent tasks in Trio.
1362
1363 Note that this is *not* an async function and you don't use await
1364 when calling it. It sets up the new task, but then returns
1365 immediately, *before* the new task has a chance to do anything.
1366 New tasks may start running in any order, and at any checkpoint the
1367 scheduler chooses - at latest when the nursery is waiting to exit.
1368
1369 It's possible to pass a nursery object into another task, which
1370 allows that task to start new child tasks in the first task's
1371 nursery.
1372
1373 The child task inherits its parent nursery's cancel scopes.
1374
1375 Args:
1376 async_fn: An async callable.
1377 args: Positional arguments for ``async_fn``. If you want
1378 to pass keyword arguments, use
1379 :func:`functools.partial`.
1380 name: The name for this task. Only used for
1381 debugging/introspection
1382 (e.g. ``repr(task_obj)``). If this isn't a string,
1383 :meth:`start_soon` will try to make it one. A
1384 common use case is if you're wrapping a function
1385 before spawning a new task, you might pass the
1386 original function as the ``name=`` to make
1387 debugging easier.
1388
1389 Raises:
1390 RuntimeError: If this nursery is no longer open
1391 (i.e. its ``async with`` block has
1392 exited).
1393 """
1394 GLOBAL_RUN_CONTEXT.runner.spawn_impl(async_fn, args, self, name)
1395
1396 # Typing changes blocked by https://github.com/python/mypy/pull/17512
1397 async def start( # type: ignore[explicit-any]

Calls 1

spawn_implMethod · 0.80