This API is awkward, inefficient, incoherent, and unintuitive. The bug
fix for which it was originally added was abandoned in favour of a
different approach, so it was never used. It appears that no consumers
are currently calling it. It would be best if none started.
Add a deprecation warning to discourage its use and allow us to remove
it altogether at some point in the future.
Change-Id: I9559c7051024019fac957385faced645920b815c
There were no docstrings for this API, which as a bonus is extremely
subtle and poorly-designed. Document it so that users at least have a
fighting chance of using it to do the things they intended.
Change-Id: Id6677a7e5aaf8ec9ddeb597c6d5e8f97806e2248
ThreadGroup add_dynamic_timer_args and add_timer_args use
DynamicLoopingCall and FixedIntervalLoopingCall respectively. Both
classes have support for stop_on_exception, but this parameter was not
exposed in ThreadGroup functions to create timers.
This change adds the missing stop_on_exception to the timer functions so
that ThreadGroup timers can continue on exceptions if the user chooses
to do so.
Change-Id: If03276f290e86e95ddc0b1d749b7460ed752b8ef
Co-Authored-By: Zane Bitter <zbitter@redhat.com>
The ThreadGroup.add_timer() API is unintuitive, inflexible, and all
around pretty terrible. By allowing the caller to pass *args and
**kwargs, it strongly implies that you can write a wrapper like:
def add_timer(self, interval, func, *args, **kwargs):
self.group.add_timer(interval, func, *args, **kwargs)
and in fact at least 6 projects have done so (probably copying and
pasting from each other). But this is wrong, and will result in the
first positional arg intended for the callback function to be treated as
the initial_delay parameter and dropped from the list of arguments to be
passed to the callback when it is run. When called like this, the
initial_delay argument not only must be passed (preventing the caller
from relying on the default), interspersed between the callback function
and its arguments, but it must be passed as a positional and not a
keyword argument (preventing the caller from effectively documenting
what is going on):
self.group.add_timer(interval, func, None, *args, **kwargs)
We are also unable to add any further options without breaking existing
consumers.
To improve the situation in the future, add a new add_timer_args() API
that takes the args and kwargs as individual sequence/mapping parameters
rather than as variadic parameters. The above call would become:
self.group.add_timer_args(interval, func, args, kwargs)
and any optional parameters can be passed as keyword arguments. Any new
keyword arguments we might want to add can be safely added to this
method.
Calling the original add_timer() method with arguments (either
positional or keyword) intended for the callback function is now
deprecated. Those parameters could be removed in a future major release.
Change-Id: Ib2791342263e2b88c045bcc92adc8160f57a0ed6
Graceful exit is not working since we removed the timers
before waiting them to complete.
Closes-Bug: #1769825
Change-Id: I2e52b680a09d337d9b598a4826132df8c7b0b4d9
When a green thread dies quickly, it will call the linked callbacks on
the link call synchronously. In this case, an error will happen when
ThreadGroup is used, as the thread is not accounted for until the link
is done. This manages this race condition by reverting the operations to
link after.
Change-Id: Iccf6edb0dfddda54552bd8787f64da84486061b7
Closes-Bug: #1662939
Instead of using time.time and such directly the
oslo utils timeutils code provides a handy timer that
itself uses monotonic time (so it won't be affected
by time shifts) so prefer to use that for the timer like
code that exists in this new cancel code.
Change-Id: Ie41f8e90cf1cb3f62fd0def00b0bc7068acd2c40
Bandit is a tool designed to find common security issues in
Python code. This change adds a bandit target to tox.ini.
The config file bandit.yaml was generated using bandit-config-generator
Run bandit:
tox -e bandit
Change-Id: I3bd64e1e58d4dc460ce869c50818e9913fe1b9b8
It seems bad to remove timer objects for timers that
didn't actually stop, so instead of removing all the
timers (including the ones that had issues) only
remove the ones that didn't have issues.
Change-Id: I1dcb589f7f026ad8eaa9145a61c7c2c386ee438e
There is no need to pass kwargs into this function
as it can already take positional arguments natively.
Passing them natively also allows for docstrings
to be associated with them and makes it easier to determine
the expected arguments (since the function definition can
be looked at to determine the arguments, vs. having to scan
the function body).
Change-Id: I809ce203b97995552cb6d4ad915a6ba63f71af18
Because x is a custom Thread instance, and threading.current_thread()
returns a GreenThread instance, they will never be a same instance.
This patch add one more property method for Thread class to identify itself.
Change-Id: I173a0a40b417d613cd270d42e40295075cd5b71f
Signed-off-by: apporc <appleorchard2000@gmail.com>
In some cases, its useful to selectively stop
some timers and not all. This fix allows a way
for client applications to maintain a handle
on timers and be able to stop some of them
selectively.
This is needed by
https://review.openstack.org/#/c/190842/
Change-Id: Ib258c07d6dd12ef7cc9f4a6c8cbde885048ceef8
Closes-Bug: 1466661