import aiohttp
import asyncio
import config
URL = f'http://xmlriver.com/search/xml?user={config.USERID}&key={config.USERKEY}&groupby=100&loc=1007989&country=2376&lr=IW&domain=65&device=desktop&query='
async def fetch(semaphore, session, query):
await semaphore.acquire()
async with session.get(URL + query) as r:
print('started')
text = await r.text()
await asyncio.sleep(0.1)
print('finished')
semaphore.release()
async def main():
limit = asyncio.BoundedSemaphore(value=2)
async with aiohttp.ClientSession() as session:
await asyncio.wait([fetch(limit, session, '3'), fetch(limit, session, '1'), fetch(limit, session, '4'), fetch(limit, session, '5')])
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
По идее на выходе я должен получать
started
started
finished
finished
started
started
finished
finished
а по факту получаю
started
finished
started
finished
started
finished
started
finished
из-за чего это может быть?