Skip to content
Snippets Groups Projects
Commit de9266e0 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

more `ThreadCollection` methods return self, permitting writing more conciser code

parent 8f0a3499
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ venv
coverage.xml
.coverage.*
.metadata
test
lock
bin/
tmp/
......
# v2.15.2
* changed schema's file to return a file-object
* more `ThreadCollection` methods return self, permitting writing more conciser code
__version__ = '2.15.2a2'
__version__ = '2.15.2a3'
......@@ -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:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment