Matt
Matt

Reputation: 4387

Python asyncio monitoring

I've a python program which are launching a random number of asyncio coroutine. During the time my program can launch new ones and some of them can exit when they have terminated their work.

I would like to know if it's possible to report, every minute, the number of active coroutine?

Thanks

Upvotes: 2

Views: 799

Answers (1)

Andrew Svetlov
Andrew Svetlov

Reputation: 17386

You cannot launch a coroutine but could start a new task

For retrieving the number of active tasks please use len(asyncio.Task.all_tasks()).

Upd

Starting from Python 3.7 please use len(asyncio.all_tasks()) API.

Upvotes: 5

Related Questions