diff options
| author | J08nY | 2024-05-21 20:48:14 +0200 |
|---|---|---|
| committer | J08nY | 2024-05-21 20:48:14 +0200 |
| commit | dda535b3600fc3385df996da47afdecb3b3df0ef (patch) | |
| tree | 57aa7d34d880776458b31c36b471b908768f1869 /pyecsca/misc | |
| parent | 2a804b2dea0bd480a89f9decb72f35010d3436d6 (diff) | |
| download | pyecsca-dda535b3600fc3385df996da47afdecb3b3df0ef.tar.gz pyecsca-dda535b3600fc3385df996da47afdecb3b3df0ef.tar.zst pyecsca-dda535b3600fc3385df996da47afdecb3b3df0ef.zip | |
Diffstat (limited to 'pyecsca/misc')
| -rw-r--r-- | pyecsca/misc/utils.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/pyecsca/misc/utils.py b/pyecsca/misc/utils.py index e525fe0..f19009e 100644 --- a/pyecsca/misc/utils.py +++ b/pyecsca/misc/utils.py @@ -10,10 +10,12 @@ from concurrent.futures import ProcessPoolExecutor, as_completed, Future def pexec(s): + """Parse with exec.""" return parse(s, mode="exec") def peval(s): + """Parse with eval.""" return parse(s, mode="eval") @@ -55,7 +57,9 @@ class TaskExecutor(ProcessPoolExecutor): """A simple ProcessPoolExecutor that keeps tracks of tasks that were submitted to it.""" keys: List[Any] + """A list of keys that identify the futures.""" futures: List[Future] + """A list of futures submitted to the executor.""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -63,6 +67,7 @@ class TaskExecutor(ProcessPoolExecutor): self.futures = [] def submit_task(self, key: Any, fn, /, *args, **kwargs): + """Submit a task (function `fn`), identified by `key` and with `args` and `kwargs`.""" future = self.submit(fn, *args, **kwargs) self.futures.append(future) self.keys.append(key) @@ -70,9 +75,11 @@ class TaskExecutor(ProcessPoolExecutor): @property def tasks(self): + """A list of tasks that were submitted to this executor.""" return list(zip(self.keys, self.futures)) def as_completed(self) -> Generator[tuple[Any, Future], Any, None]: + """Like `concurrent.futures.as_completed`, but yields a pair of key and future.""" for future in as_completed(self.futures): i = self.futures.index(future) yield self.keys[i], future |
