Xj pddlmZmZmZddlmZddlmZmZm Z m Z m Z m Z ddl mZeZdgZGddeZy))ExecutorFutureThreadPoolExecutor) TracebackType)AnyCallableDictOptionalTupleType) EventEmitterExecutorEventEmitterc eZdZdZddedeeddffd Zdedede e d fd e e e fddf d Z dded eddfd ZdeddfdZdedeedededeef dZxZS)raAn event emitter class which runs handlers in a `concurrent.futures` executor. By default, this class creates a default `ThreadPoolExecutor`, but a custom executor may also be passed in explicitly to, for instance, use a `ProcessPoolExecutor` instead. This class runs all emitted events on the configured executor. Errors captured by the resulting Future are automatically emitted on the `error` event. This is unlike the EventEmitter, which have no error handling. The underlying executor may be shut down by calling the `shutdown` method. Alternately you can treat the event emitter as a context manager: ```py with ExecutorEventEmitter() as ee: # Underlying executor open @ee.on('data') def handler(data): print(data) ee.emit('event') # Underlying executor closed ``` Since the function call is scheduled on an executor, emit is always non-blocking. No effort is made to ensure thread safety, beyond using an executor. Nselfexecutorreturnc\tt| |r||_yt |_yN)superr__init__ _executorr)rr __class__s a/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pyee/executor.pyrzExecutorEventEmitter.__init__1s% "D24 '/DN/1DNfargs.kwargscjj|g|i|}|jdtddffd }y)Nrrct|j}t|trjd|y||y)Nerror) exception isinstance Exceptionemit)rexcrs r _callbackz1ExecutorEventEmitter._emit_run.._callback@s5+,;;=C#y) '3' !r)rsubmitadd_done_callbackr)rrrrfuturer&s` r _emit_runzExecutorEventEmitter._emit_run8sK /..qB4B6B  ! !  D  " rwaitc<|jj|y)z)Call `shutdown` on the internal executor.)r+N)rshutdown)rr+s rr-zExecutorEventEmitter.shutdownHs T*rc|Sr)rs r __enter__zExecutorEventEmitter.__enter__Ms rtypevalue tracebackc$|jyr)r-)rr1r2r3s r__exit__zExecutorEventEmitter.__exit__Ps rr)T)__name__ __module__ __qualname____doc__Selfr rrrr rr strr*boolr-r0r r#rr5 __classcell__)rs@rrrs D2t2x'92T2 CHoS#X    +t+4+4+ !7y/2;HU $rN)concurrent.futuresrrrtypesrtypingrrr r r r pyee.baser r:__all__rr/rrrCs5DC=="  ! "F<Fr