ExecutorProcessingService
class¶
Bases: ProcessingService
A processing service that utilizes the concurrent.futures.Executor
to handle the execution of calls.
Notes:
-
This service uses the
concurrent.futures.Executor
for processing the callbacks' execution. It can work with either aThreadPoolExecutor
for thread-based execution or aProcessPoolExecutor
for process-based execution. -
Synchronous callbacks are executed in a blocking manner inside the executor, while asynchronous callbacks are processed within a new asyncio event loop using the
asyncio.run()
function. -
When using this service, it is important to properly manage the underlying
Executor
. Once there are no more calls to be processed through the given executor, it's important to invoke theshutdown()
method to signal the executor to free any resources for pending futures. You can avoid the need to call this method explicitly by using thewith
statement, which automatically shuts down theExecutor
.
Source code in pyventus/core/processing/executor/executor_processing_service.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
Functions¶
__init__
¶
Initialize an instance of ExecutorProcessingService
.
PARAMETER | DESCRIPTION |
---|---|
executor
|
The executor object used to handle the callbacks' execution.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
PyventusException
|
If the executor is not provided or is not an instance of |
Source code in pyventus/core/processing/executor/executor_processing_service.py
submit
¶
Source code in pyventus/core/processing/executor/executor_processing_service.py
shutdown
¶
Shut down the executor and release any resources it is using.
PARAMETER | DESCRIPTION |
---|---|
wait
|
A boolean indicating whether to wait for the currently pending futures to complete before shutting down.
TYPE:
|
cancel_futures
|
A boolean indicating whether to cancel any pending futures.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in pyventus/core/processing/executor/executor_processing_service.py
__enter__
¶
Return the current instance of ExecutorProcessingService
for context management.
RETURNS | DESCRIPTION |
---|---|
Self
|
The current instance of |
Source code in pyventus/core/processing/executor/executor_processing_service.py
__exit__
¶
__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Clean up the executor resources when exiting the context.
PARAMETER | DESCRIPTION |
---|---|
exc_type
|
The exception type, if any.
TYPE:
|
exc_val
|
The exception value, if any.
TYPE:
|
exc_tb
|
The traceback information, if any.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |