caikit.core.toolkit.concurrency.destroyable_thread
Attributes
Exceptions
Exception raised inside a DestroyableThread when it is destroyed by the thread managing |
Classes
A class for Destroyable Threads. When work is delegated to a thread but may need to be |
Module Contents
- exception caikit.core.toolkit.concurrency.destroyable_thread.ThreadDestroyedException[source]
Bases:
RuntimeErrorException raised inside a DestroyableThread when it is destroyed by the thread managing its lifecycle.
- class caikit.core.toolkit.concurrency.destroyable_thread.DestroyableThread(runnable_func, *runnable_args, work_done_event: threading.Event | None = None, **runnable_kwargs)[source]
Bases:
threading.Thread,caikit.core.toolkit.concurrency.destroyable.DestroyableA class for Destroyable Threads. When work is delegated to a thread but may need to be canceled while in progress, we use this class which allows us to raise an exception inside the work thread.
Exceptions raised this way are asynchronous and they will not interrupt the python instruction that the thread is currently executing. E.g. a time.sleep() will finish sleeping before the exception is raised.
This class may be initialized with a threading event, which it will set when the thread finishes executing, whether nominally or by raising an exception.
- __exception
- work_done_event
- runnable_func
- runnable_args = ()
- runnable_kwargs
- __runnable_result = None
- __runnable_exception = None
- __threw = False
- __started = False
- __ran = False
- __destroyed = False
- property destroyed: bool
Return True if destroy was called, regardless of whether the destroyable was alive at the time
- property canceled: bool
Returns True if destroyed while actively working
- property ran: bool
Return True if the destroyable completed execution in any state
- property threw: bool
Return True if any exception was raised during execution
- destroy() None[source]
Cancel any in-progress work and kill the thread if it is alive. Otherwise, prevent the thread from running at all.
- Returns:
None
- property error: Exception | None
Return the error information to user if one occurred
- __get_id()
- __raise()