patroni.async_executor module
Implement facilities for executing asynchronous tasks.
- class _patroni.async_executor.AsyncExecutor(_cancellable: CancellableSubprocess, ha_wakeup: Callable[[…], None]) View on GitHub
-
Bases:
object
+ Asynchronous executor of (long) tasks. +- Variables:
-
critical_task – a
CriticalTask
instance to handle execution of critical background tasks. + - __init\\__(cancellable: CancellableSubprocess, ha_wakeup: Callable[[…], None]) → None View on GitHub
-
Create a new instance of
AsyncExecutor
. + Configure the given cancellable and ha_wakeup, initializes the control attributes, and instantiate the lock and event objects that are used to access attributes and manage communication between threads. +- Parameters
-
+
- property _busy: bool_
-
True
if there is an action scheduled to occur, elseFalse
. + - cancel() → None View on GitHub
-
Request cancellation of a scheduled async task, if any. + Note
Wait until task is cancelled before returning control to caller. +
- reset_scheduled_action() → None View on GitHub
-
Unschedule a previously scheduled action, if any. + Note
Must be called once the scheduled task finishes or is cancelled. +
- run(func: Callable[[…], Any], args: Tuple[ Any, …] = ()) → Any | None View on GitHub
-
Run func with args. + Note
Expected to be executed through a thread. + Parameters::: Returns::: `+None+` if _func_ execution has been cancelled or faced any exception, otherwise the result of _func_. +
- run_async(func: Callable[[…], Any], args: Tuple[ Any, …] = ()) → None View on GitHub
-
Start an async thread that runs func with args. +
- Parameters
-
+
- schedule(action: str) → str | None View on GitHub
-
Schedule action to be executed. + Note
Must be called before executing a task. + Note
_action_ can only be scheduled if there is no other action currently scheduled. + Parameters::: *action* – action to be executed. Returns::: `+None+` if _action_ has been successfully scheduled, or the previously scheduled action, if any. +
- property _scheduled_action: str | None_
-
The currently scheduled action, if any, else
None
. + - try_run_async(action: str, func: Callable[[…], Any], args: Tuple[ Any, …] = ()) → str | None View on GitHub
-
Try to run an async task, if none is currently being executed. +
- Parameters
- Returns
-
None
if func was scheduled successfully, otherwise an error message informing of an already ongoing task.
- _class _patroni.async_executor.CriticalTask View on GitHub
-
Bases:
object
+ Represents a critical task in a background process that we either need to cancel or get the result of. + Fields of this object may be accessed only when holding a lock on it. To perform the critical task the background thread must, while holding lock on this object, checkis_cancelled
flag, run the task and mark the task as complete usingcomplete()
. + The main thread must hold async lock to prevent the task from completing, hold lock on critical task object, callcancel()
. If the task has completedcancel()
will returnFalse
andresult
field will contain the result of the task. Whencancel()
returnsTrue
it is guaranteed that the background task will notice theis_cancelled
flag. +- Variables:
-
+
- __init\\__() → None View on GitHub
-
Create a new instance of
CriticalTask
.
Instantiate the lock and the task control attributes. + - cancel() → bool View on GitHub
-
Tries to cancel the task. + Note
Caller must hold lock on async executor and the task when calling. + Returns::: `+False+` if the task has already run, or `+True+` it has been cancelled. +
- complete(result: Any) → None View on GitHub
-
Mark task as completed along with a result. + Note
Must be called from async thread. Caller must hold lock on task when calling. +
- reset() → None View on GitHub
-
Must be called every time the background task is finished. + Note
Must be called from async thread. Caller must hold lock on async executor when calling.
© Copyright 2015 Compose, Zalando SE. Revision 9d231aee
.
Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
+ Builds