Code Monkey home page Code Monkey logo

repeat_until_no_exceptions's Introduction

repeat_until_no_exceptions

from repeat import repeat_until_no_exceptions

TEST

Test code

from random import randint

@repeat_until_no_exceptions(5, 2, IndexError)
def test_func(test_list: list):
    rdm_idx = randint(0, 10)
    print(f'{rdm_idx = }')
    return test_list[rdm_idx]

Success in 5 chances

test_func(['a', 'b', 'c', 'd'])
rdm_idx = 4
[Chance : 5] "test_func" will be re-executed after 2 sec.

rdm_idx = 10
[Chance : 4] "test_func" will be re-executed after 2 sec.

rdm_idx = 3
'd'

Failure in 5 chances

test_func(['a'])
rdm_idx = 5
[Chance : 5] "test_func" will be re-executed after 2 sec.

rdm_idx = 2
[Chance : 4] "test_func" will be re-executed after 2 sec.

rdm_idx = 9
[Chance : 3] "test_func" will be re-executed after 2 sec.

rdm_idx = 9
[Chance : 2] "test_func" will be re-executed after 2 sec.

rdm_idx = 6
[Chance : 1] "test_func" will be re-executed after 2 sec.

Exhaustion of all chances



---------------------------------------------------------------------------

TimeoutError          Traceback (most recent call last)

File ~/repetition_until_no_exception/repeat.py:15, in repeat.<locals>.a.<locals>.b(*args, **kwargs)
     13         time.sleep(waiting_second)
     14 print(f'Exhaustion of all chances')
---> 15 raise TimeoutError


TimeoutError: 

repeat_until_no_exceptions's People

Contributors

plusjob70 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.