Giter Club home page Giter Club logo

Comments (7)

jd avatar jd commented on August 20, 2024

I am sorry but it's not really clear. Can you provide a full small example of what you can't and want to achieve?

Keep in mind this is a retrying library. Not a general iteration library.

from tenacity.

georgepsarakis avatar georgepsarakis commented on August 20, 2024

@cher-nov as you said I think you need to separate the logic into two different functions, the main/current one that contains the while loop and another one that will use retrying:

def main_function():
     previous_job = None
     while not stop_event.is_set():
         current_job = process_job(..., previous=previous_job)
         # ...
         previous_job = current_job

@retry(stop=stop_after_attempt(3))
def process_job(..., previous=None):
    ...

from tenacity.

cher-nov avatar cher-nov commented on August 20, 2024

@georgepsarakis Thank you, I know about this workaround, but the problem is that I need data from ALL jobs done.

from tenacity.

cher-nov avatar cher-nov commented on August 20, 2024

@jd

@retry(stop=stop_after_attempt(3))
def test_function():
    # while loop that does jobs
    # every successful iteration is a completed job
    while not stop_event.is_set():
        # some code that can raise exception #
        test_function.retry.attempt_number = 1  # <-- something like that,
                                                # but at the library-level

from tenacity.

jd avatar jd commented on August 20, 2024

@cher-nov you're providing a solution in #76 (comment) but I would actually like to know what's the problem in the solution proposed by @georgepsarakis in #76 (comment)

IIUC all you want to do is to retry each job up to 3 times and give up if it fails. That's what @georgepsarakis wrote. You can store all the job result in a list if you need them all in the end.

from tenacity.

cher-nov avatar cher-nov commented on August 20, 2024

You can store all the job result in a list if you need them all in the end.

this. But to access that list I must either write process_job function as nested or pass it a reference to the list. Both solutions not so beautiful IMHO. :)

from tenacity.

jd avatar jd commented on August 20, 2024

Writing functional code and separating the retry condition from the general workflow still sounds better to me.

Also you can do something like

attempt = stop_after_attempt(3)

@retry(stop=attempt)
def test_function():
    # while loop that does jobs
    # every successful iteration is a completed job
    while not stop_event.is_set():
        # some code that can raise exception
        attempt.max_attempt_number += 1

Or write your own stop function/class in the end. :)

from tenacity.

Related Issues (20)

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.