title: Why doesn't this asyncio semaphore implementation work with aiohttp in python
body: <p>I first make a simple request to get a JSON containing all the names, then I iterate over all the names and make asynchronous awaitable calls corresponding to each name, and store them in a list called &quot;tasks&quot;, and then I gather all of them.</p>
  <p>The problem is, the response server has a limit to the api responses per minute, and no matter how low I keep the semaphore value, this code takes the same time (small enough to not meet the server's expectations) to make the API calls, as if the semaphore doesn't exist at all. How do I control the API call rate?</p>
  <pre><code>&lt;some code&gt;    
  url = http://example.com/
  response = requests.request(&quot;GET&quot;, url, headers=headers)    
  
  async def get_api(session, url_dev):
      async with session.get(url_dev, headers = headers) as resp:
          result = await resp.json()
          return result
  
  async def main():
      async with aiohttp.ClientSession() as session:
          sem = asyncio.Semaphore(1)
          tasks = []
          for i in response.json()[&quot;Names&quot;]:
  
              url_dev = &quot;https://example.com/example/&quot; + str(i[&quot;Id&quot;])
              await sem.acquire()
              async with sem:
                  tasks.append(asyncio.create_task(get_api(session, url_dev)))
  
  
          full_list = list()
          async with sem:
              full_list = await asyncio.gather(*tasks)
  
  asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  asyncio.run(main())
  </code></pre>