import asyncio
import random


@asyncio.coroutine
def main():
    pool = asyncio.Queue()
    pool.put_nowait(1)
    pool.put_nowait(2)
    pool.put_nowait(3)

    @asyncio.coroutine
    def pooled(coro):
        id = yield from pool.get()
        print('+ task')
        try:
            return (yield from coro)
        finally:
            print('- task')
            pool.put_nowait(id)

    tasks = [
        pooled(asyncio.sleep(random.randint(1, 2)))
        for i in range(10)
    ]

    yield from asyncio.wait(tasks)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())