[Python-Dev] A more flexible task creation (original) (raw)
Tin Tvrtković tinchester at gmail.com
Thu Jun 14 18:31:12 EDT 2018
- Previous message (by thread): [Python-Dev] A more flexible task creation
- Next message (by thread): [Python-Dev] A more flexible task creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Jun 14, 2018 at 10:03 PM Steve Dower <steve.dower at python.org> wrote:
I often use semaphores for this when I need it, and it looks like asyncio.Semaphore() is sufficient for this:
import asyncio tasklimiter = asyncio.Semaphore(4) async def mytask(): await tasklimiter.acquire() try: await dodbrequest() finally: tasklimiter.release()
Yeah, a semaphore logically fits exactly but
I feel this API is somewhat clunky, even if you use an 'async with'.
my gut feeling is spawning a thousand tasks and having them all fighting over the same semaphore and scheduling is going to be much less efficient than a small number of tasks draining a queue. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180615/06a63c74/attachment.html>
- Previous message (by thread): [Python-Dev] A more flexible task creation
- Next message (by thread): [Python-Dev] A more flexible task creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]