Skip to content

17th November 2021

Computer Science

Programming

asyncio

  • New: Limit concurrency.

    Use asyncio.Semaphore.

    sem = asyncio.Semaphore(10)
    
    async with sem:
        # work with shared resource
    

Other

  • New: Retrying library for Python.

    from tenacity import retry, stop_after_attempt, wait_exponential
    
    @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=0.1))
    def somefunction():
      raise Exception
    

    The function will be retried a maximum of 3 times, waiting 0.1 s, 0.2 s and 0.4 s between each attempt respectively.