diff options
Diffstat (limited to 'pyecsca/misc/utils.py')
| -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 |
