News for hackers. Stuff that matters.
Re:Opnieuw: A simple and intuitive retrying library for Python by m12k on Wednesday February 05, 2020 @07:51AM (#22246294)
If you're using something like this, then the details of when, what and how you retry is probably something you care about, so having the library be explicit about it and making it possible to know what something means without having to look at the docs seems sensible to me.
Re:Opnieuw: A simple and intuitive retrying library for Python by anton_gogolev on Wednesday February 05, 2020 @08:06AM (#22246380)
This is some Java-level explicitness. Maybe, drop the `_seconds` suffix and replace it with something like `retry_window_after_first_call = '60s'`?
Re:Opnieuw: A simple and intuitive retrying library for Python by tijmendj on Wednesday February 05, 2020 @08:20AM (#22246463)
I agree it might look a bit excessive, but it greatly cuts down on complexity and possible unexpected behavior.

If you accept '60s' as 60 seconds, then the next questions are:

- Will it also accept '60000ms'?

- What does it do if I pass an int or float anyway? Will it implicitly take it to be seconds?

- Will it throw an exception if I use an unexpected value? If so, which exceptions can I expect? Will it just chug along and use a default?

Re:Opnieuw: A simple and intuitive retrying library for Python by VBprogrammer on Wednesday February 05, 2020 @08:46AM (#22246629)
Something I picked up from another developer is to use timedelta for these type of parameters. It avoids hoping that you get the right granularity for everyone.

   retry_window_after_first_call=timedelta(minutes=3.5)
   retry_window_after_first_call=timedelta(days=2)
   retry_window_after_first_call=timedelta(minutes=50)
Re:Opnieuw: A simple and intuitive retrying library for Python by leetrout on Thursday February 06, 2020 @03:02PM (#22259732)
Nice! Yes this is the better option. IMO, should just be

  retry_window=timedelta(...)
Re:Opnieuw: A simple and intuitive retrying library for Python by mercer on Wednesday February 05, 2020 @10:04AM (#22247241)
While the idea of '60s' is interesting, in lieu of that I always err on the side of explicitly specifying the time units when the argument provided is just a number. Not doing so has bitten me too many times.
Re:Opnieuw: A simple and intuitive retrying library for Python by bluebasket on Wednesday February 05, 2020 @08:49AM (#22246649)
60s. was wondering how we could add physical units to python? highjack the number literals and variables like this: 1.s, pi.radians? or maybe the way golang does it: 1 * time.seconds?

would be nice to have

Re:Opnieuw: A simple and intuitive retrying library for Python by bobbiechen on Wednesday February 05, 2020 @12:55PM (#22249315)
I also found this package: https://github.com/sbyrnes321/numericalunits

Which uses the interesting approach of setting all "units" to random floats: A complete set of independent base units (meters, kilograms, seconds, coulombs, kelvins) are defined as randomly-chosen positive floating-point numbers. All other units and constants are defined in terms of those. In a dimensionally-correct calculation, the units all cancel out, so the final answer is deterministic, not random. In a dimensionally-incorrect calculations, there will be random factors causing a randomly-varying final answer.

Which presumably is done to avoid overhead from carrying around units with each number, but forces you to run calculations multiple times (with different random seeds) to verify the result is correct.

Re:Opnieuw: A simple and intuitive retrying library for Python by magnusmundus on Wednesday February 05, 2020 @12:03PM (#22248729)
Re:Opnieuw: A simple and intuitive retrying library for Python by ekimekim on Wednesday February 05, 2020 @11:34AM (#22248377)
Sounds like a fun hack, I encourage you to give it a try and then never EVER use it in real code :P