Bases: object
Wrapper around a greenthread.
Holds a reference to the ThreadGroup
. The Thread will notify
the ThreadGroup
when it has done so it can be removed from
the threads list.
Prevent the thread from starting if it has not already done so.
throw_args – the exc_info data to raise from wait()
.
Schedule a function to be run upon completion of the thread.
Kill the thread by raising GreenletExit within it.
Block until the thread completes and return the result.
Bases: object
A group of greenthreads and timers.
The point of the ThreadGroup class is to:
keep track of timers and greenthreads (making it easier to stop them when need be).
provide an easy API to add timers.
Note
The API is inconsistent, confusing, and not orthogonal. The same verbs often mean different things when applied to timers and threads, respectively. Read the documentation carefully.
Add a timer that controls its own period dynamically.
The period of each iteration of the timer is controlled by the return value of the callback function on the previous iteration.
Warning
Passing arguments to the callback function is deprecated. Use the
add_dynamic_timer_args()
method to pass arguments for the
callback function.
callback – The callback function to run when the timer is triggered.
initial_delay – The delay in seconds before first triggering the timer. If not set, the timer is liable to be scheduled immediately.
periodic_interval_max – The maximum interval in seconds to allow the callback function to request. If provided, this is also used as the default delay if None is returned by the callback function.
an oslo_service.loopingcall.DynamicLoopingCall
instance
Add a timer that controls its own period dynamically.
The period of each iteration of the timer is controlled by the return value of the callback function on the previous iteration.
callback – The callback function to run when the timer is triggered.
args – A list of positional args to the callback function.
kwargs – A dict of keyword args to the callback function.
initial_delay – The delay in seconds before first triggering the timer. If not set, the timer is liable to be scheduled immediately.
periodic_interval_max – The maximum interval in seconds to allow the callback function to request. If provided, this is also used as the default delay if None is returned by the callback function.
stop_on_exception – Pass False
to have the timer continue
running even if the callback function raises
an exception.
an oslo_service.loopingcall.DynamicLoopingCall
instance
Spawn a new thread.
This call will block until capacity is available in the thread pool. After that, it returns immediately (i.e. before the new thread is scheduled).
callback – the function to run in the new thread.
args – positional arguments to the callback function.
kwargs – keyword arguments to the callback function.
a Thread
object
Add a timer with a fixed period.
Warning
Passing arguments to the callback function is deprecated. Use the
add_timer_args()
method to pass arguments for the callback
function.
interval – The minimum period in seconds between calls to the callback function.
callback – The callback function to run when the timer is triggered.
initial_delay – The delay in seconds before first triggering the timer. If not set, the timer is liable to be scheduled immediately.
an oslo_service.loopingcall.FixedIntervalLoopingCall
instance
Add a timer with a fixed period.
interval – The minimum period in seconds between calls to the callback function.
callback – The callback function to run when the timer is triggered.
args – A list of positional args to the callback function.
kwargs – A dict of keyword args to the callback function.
initial_delay – The delay in seconds before first triggering the timer. If not set, the timer is liable to be scheduled immediately.
stop_on_exception – Pass False
to have the timer continue
running even if the callback function raises
an exception.
an oslo_service.loopingcall.FixedIntervalLoopingCall
instance
Cancel unstarted threads in the group, and optionally stop the rest.
Warning
This method is deprecated and should not be used. It will be removed in a future release.
If called without the timeout
argument, this does not stop any
running threads, but prevents any threads in the group that have not
yet started from running, then returns immediately. Timers are not
affected.
If the ‘timeout’ argument is supplied, then it serves as a grace period
to allow running threads to finish. After the timeout, any threads in
the group that are still running will be killed by raising GreenletExit
in them, and all timers will be stopped (so that they are not
retriggered - timer calls that are in progress will not be
interrupted). This method will not block until all threads have
actually exited, nor that all in-progress timer calls have completed.
To guarantee that all threads have exited, call wait()
. If all
threads complete before the timeout expires, timers will be left
running; there is no way to then stop those timers, so for consistent
behaviour :func`stop_timers` should be called before calling this
method.
throw_args – the exc_info data to raise from
Thread.wait()
for any of the unstarted
threads. (Though note that ThreadGroup.wait()
suppresses exceptions.)
timeout – time to wait for running threads to complete before calling stop(). If not supplied, threads that are already running continue to completion.
wait_time – length of time in seconds to sleep between checks of whether any threads are still alive. (Default 1s.)
Stop all timers and threads in the group.
No new invocations of timers will be triggered after they are stopped, but calls that are in progress will not be interrupted.
If graceful
is false, kill all threads immediately by raising
GreenletExit. Note that in this case, this method will not block
until all threads and running timer callbacks have actually exited. To
guarantee that all threads have exited, call wait()
.
If graceful
is true, do not kill threads. Block until all threads
and running timer callbacks have completed. This is equivalent to
calling stop_timers()
with wait=True
followed by
wait()
.
graceful – If true, block until all timers have stopped and all threads completed; never kill threads. Otherwise, kill threads immediately and return immediately even if there are timer callbacks still running.
Stop all timers in the group and remove them from the group.
No new invocations of timers will be triggered after they are stopped, but calls that are in progress will not be interrupted.
To wait for in-progress calls to complete, pass wait=True
- calling
wait()
will not have the desired effect as the timers will have
already been removed from the group.
wait – If true, block until all timers have been stopped before returning.
Remove a completed thread from the group.
This method is automatically called on completion of a thread in the group, and should not be called explicitly.
Remove a timer from the group.
timer – The timer object returned from add_timer()
or its
analogues.
Block until all timers and threads in the group are complete.
Note
Before calling this method, any timers should be stopped first by
calling stop_timers()
, stop()
, or cancel()
with a
timeout
argument. Otherwise this will block forever.
Note
Calling stop_timers()
removes the timers from the group, so a
subsequent call to this method will not wait for any in-progress
timer calls to complete.
Any exceptions raised by the threads will be logged but suppressed.
Note
This call guarantees only that the threads themselves have
completed, not that any cleanup functions added via
Thread.link()
have completed.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.