Do finished tasks take up resources?

Hello,

Do finished tasks take up resources? In other words, will the following code consume unbounded memory, or are the tasks fully cleaned up once they exit cleanly?


async def do_work():
  await trio.sleep(1)

async with trio.open_nursery() as nursery:
  nursery.start_soon(do_work)
  await trio.sleep(1)

(Background of my question: I’m wondering if, in a server application, I can safely start new tasks to handle incoming requests, or if I need to create a pool of long-running tasks that receive requests through a memory channel).

No they don’t, and starting a new task for each request is a perfectly valid approach (and pretty much the natural solution).

Some people have occasionally requested that nurseries remember the return values from their child tasks so that they can be inspected when the nursery finishes. One of the (several) objections to this is exactly that it would cause unbounded memory usage in this sort of scenario.