Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How to add a percent_jitter strategy to backoff Python package and pass extra args in the decorator?

Post

How to add a percent_jitter strategy to backoff Python package and pass extra args in the decorator?

+6
−0

I'm trying to add a percent-based jitter function to the backoff package and use that modified package in my project instead of the PyPI release.

Current jitter algorithm I want to implement (from Stack Overflow):
https://stackoverflow.com/q/46939285

Proposed function:

def percent_jitter(value: float, percentage: float = 0.2) -> float:
    max_jitter = value * percentage
    return value + random.uniform(-max_jitter, max_jitter)

Questions:

  1. What is the best way to modify the backoff package source to add this percent_jitter function? The existing jitter functions are called with only the backoff value. I would need to modify the library so a jitter function can accept an extra parameter (like percentage) and let users pass that parameter when applying the @backoff.on_exception with jitter=percent_jitter(percentage={input}).
  2. How can I install and use my modified version in my project instead of the PyPI package?
  3. Alternatively, if modifying the library is too complex, how can I use this custom jitter function with the original backoff package?
History

1 comment thread

Focus and subjectivity (2 comments)
Focus and subjectivity
Karl Knechtel‭ wrote 11 months ago

I see this question going in two very different directions, and I would probably close it until that were addressed, if the site were busier, but it's not as big of an issue as with the other question I just closed.

The specific question about making a change to this library is, I think, not a good fit for the Q&A format. it would require analysis of a bunch of off-site code, as well as inserting a lot of subjectivity and design work. If you need to understand how to rewrite a function to take an extra parameter, or modify a "plain" decorator to start taking parameters, etc. then that should be asked with a more concrete, focused example.

However, I'd be happy to answer a question that's explicitly about the general process of modifying and distributing third-party code, because that's an important problem that actually has clear general approaches to solutions and doesn't really need to be broken down any further.

Karl Knechtel‭ wrote 11 months ago

As for the alternate proposed approach, both whether it's feasible and how it would work depend on a proper MRE. Even if the project is documented well enough to figure out an answer, there should be a context for that answer: we should see an existing demo use of @backoff.on_exception in order to describe a modified use (and compare and contrast it).

In particular, it sounds as if you want the percentage of jitter to be determined at runtime, and are struggling with the fact that a decorator with standard @ syntax would be applied before the user is actually prompted for that value. If that's really what the question is about, then that's what you should directly ask about.