GithubHelp home page GithubHelp logo

aio_retrying's Introduction

aio_retrying

info:Simple retrying for asyncio

Installation

pip install aio_retrying

Usage

import asyncio

import aiohttp

from Utils.async_retrying import retry


class Aio:
    def __init__(self):
        self.session = aiohttp.ClientSession()

    async def __aenter__(self):
        return self

    @retry(attempts=3, delay=1, fallback="daoji")
    async def __aexit__(self, exc_type, exc_val, exc_tb):
        await self.session.close()
        print("exit")

    async def main(self):
        for i in range(3):
            assert self.session.closed is False
            await asyncio.sleep(1)
            print(f"task - {i}")


async def second_aio():
    aio = Aio()
    # task = asyncio.create_task(aio.main())
    # task.add_done_callback(lambda _: asyncio.create_task(aio.__aexit__(None, None, None)))
    ret = await aio.__aexit__(None, None, None)
    print(f"结果:{ret}")


async def first_aio():
    await second_aio()
    while True:
        # print("first")
        await asyncio.sleep(3)


def main():
    asyncio.run(first_aio())


if __name__ == "__main__":
    main()

Python 3.8+ is required

aio_retrying's People

Contributors

hellysmile avatar kvirt avatar mikenemkov avatar daojianime avatar litwisha avatar

Stargazers

canghaitan avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.