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

add kwargs

parent dda930e4
No related branches found
No related tags found
No related merge requests found
# v2.14.46
* added kwargs to ThreadCollection.from_class
__version__ = '2.14.46a1'
__version__ = '2.14.46a2'
......@@ -11,7 +11,7 @@ class ThreadCollection:
>>> class MyThread(Thread):
>>> def __init__(self, a):
>>> ...
>>> tc = ThreadCollection.from_class(MyThread, [2, 4, 5])
>>> tc = ThreadCollection.from_class(MyThread, [2, 4, 5], daemon=True)
>>> tc.start()
>>> tc.terminate()
>>> tc.join()
......@@ -20,14 +20,28 @@ class ThreadCollection:
__slots__ = ('threads', )
@classmethod
def from_class(cls, cls_to_use, iteratable) -> 'ThreadCollection':
def from_class(cls, cls_to_use, iteratable, **kwargs) -> 'ThreadCollection':
"""
Build a thread collection
:param cls_to_use: class to instantiate with
:param iteratable: an iterable with the sole argument to this class
"""
return ThreadCollection([cls_to_use(it) for it in iteratable])
return ThreadCollection([cls_to_use(it, **kwargs) for it in iteratable])
@property
def daemon(self) -> bool:
"""
Is any of the threads a daemon?
Also, when used a setter sets daemon attribute.
"""
return any(thread.daemon for thread in self.threads)
@daemon.setter
def daemon(self, v: bool) -> None:
for thread in self.threads:
thread.daemon = v
def __init__(self, threads: tp.List[Thread]):
self.threads = threads
......
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