ExecutorEventEmitter
class¶
Bases: EventEmitter
An event emitter subclass that utilizes the concurrent.futures
Executor base class to
handle the execution of event emissions. It can work with either ThreadPoolExecutor
for thread-based execution or ProcessPoolExecutor
for process-based execution.
Notes:
- When using this event emitter, it is important to properly manage the underlying
Executor
. Once you have finished emitting events, call 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 will automatically shut down theExecutor
(waiting as ifExecutor.shutdown()
were called withwait
set toTrue
).
Read more in the Pyventus docs for Executor Event Emitter.
Source code in pyventus/emitters/executor/executor_event_emitter.py
Functions¶
emit
¶
Emits an event and triggers its associated event handlers.
Notes:
- When emitting
dataclass
objects orException
objects, they are automatically passed to the event handler as the first positional argument, even if you pass additional*args
or**kwargs
. - If there are event handlers subscribed to the global event
...
, also known asEllipsis
, they will also be triggered each time an event or exception is emitted.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to be emitted. It can be
TYPE:
|
args
|
Positional arguments to be passed to the event handlers.
TYPE:
|
kwargs
|
Keyword arguments to be passed to the event handlers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in pyventus/emitters/event_emitter.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
__init__
¶
__init__(executor: Executor = ThreadPoolExecutor(), event_linker: Type[EventLinker] = EventLinker, debug: bool | None = None) -> None
Initialize an instance of ExecutorEventEmitter
.
PARAMETER | DESCRIPTION |
---|---|
executor
|
The executor object used to handle the execution of event emissions. Defaults to
TYPE:
|
event_linker
|
Specifies the type of event linker used to manage and access events along with their corresponding event handlers. Defaults to
TYPE:
|
debug
|
Specifies the debug mode for the logger. If
TYPE:
|
Source code in pyventus/emitters/executor/executor_event_emitter.py
__enter__
¶
__enter__() -> ExecutorEventEmitter
Returns the current instance of ExecutorEventEmitter
for context management.
RETURNS | DESCRIPTION |
---|---|
ExecutorEventEmitter
|
The current instance of |
__exit__
¶
__exit__(exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Cleans 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 |
Source code in pyventus/emitters/executor/executor_event_emitter.py
shutdown
¶
Shuts down the executor and frees 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 |