diff --git a/.gitignore b/.gitignore index 79cb29c0179a4d8164b1eaafa4642e9ac79e28db..78583dae7e3b0952ba8154a6aa00c8ea94a89db6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ venv coverage.xml .coverage.* .metadata +test lock bin/ tmp/ diff --git a/CHANGELOG.md b/CHANGELOG.md index ba20c57c0ed89644438e348350597c74ed906bbe..6aebe3d0b99a965ed8eda175def48cf5f5cc21d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ # v2.15.2 * changed schema's file to return a file-object - +* more `ThreadCollection` methods return self, permitting writing more conciser code diff --git a/satella/__init__.py b/satella/__init__.py index 658de0a4a2c70c8180654b5dacc1877820fbad95..919cebbcfbb290b65101f0d617fb102fc14eea64 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.15.2a2' +__version__ = '2.15.2a3' diff --git a/satella/coding/concurrent/thread_collection.py b/satella/coding/concurrent/thread_collection.py index e138022b8fa434374b1630329f0b305f3be22237..41110b981db36d3391ba25f541497955ad2df9d0 100644 --- a/satella/coding/concurrent/thread_collection.py +++ b/satella/coding/concurrent/thread_collection.py @@ -73,43 +73,58 @@ class ThreadCollection: def __init__(self, threads: tp.Sequence[Thread]): self.threads = list(threads) - def append(self, thread: Thread) -> None: + def append(self, thread: Thread) -> 'ThreadCollection': """ Alias for :meth:`~satella.coding.concurrent.ThreadCollection.add` :param thread: thread to add + :returns: this thread collection instance """ self.add(thread) + return self - def add(self, thread: Thread) -> None: + def add(self, thread: Thread) -> 'ThreadCollection': """ Add a thread to the collection :param thread: thread to add + :returns: this thread collection instance """ self.threads.append(thread) + return self - def start(self) -> None: + def start(self) -> 'ThreadCollection': """ Start all threads + + :returns: this thread collection instance """ for thread in self.threads: thread.start() + return self - def terminate(self, *args, **kwargs) -> None: + def terminate(self, *args, **kwargs) -> 'ThreadCollection': """ Call terminate() on all threads that have this method + + :returns: this thread collection instance """ for thread in self.threads: try: thread.terminate(*args, **kwargs) except AttributeError: pass + return self - def join(self) -> None: - """Join all threads""" + def join(self) -> 'ThreadCollection': + """ + Join all threads + + :returns: this thread collection instance + """ for thread in self.threads: thread.join() + return self def is_alive(self) -> bool: """