diff --git a/Lib/threading.py b/Lib/threading.py --- a/Lib/threading.py +++ b/Lib/threading.py @@ -745,6 +745,34 @@ # Main class for threads +class SimpleThreadGroup: + 'A minimal featured class for aggregating related threads' + + def __init__(self, name): + self.name = name + self.threads = [] + + def _add(self, thread): + 'Add a thread to the group' + self.threads.append(thread) + + def __repr__(self): + return '{0.__class__.__name__}({0.name})'.format(self) + + def __iter__(self): + # ??? does this need locks or some such + return iter(list(self.threads)) + + def start(self): + 'Start all threads in the group' + for thread in self.threads: + thread.start() + + def join(self): + 'Wait for all threads in the group' + for thread in self.threads: + thread.join() + class Thread: """A class that represents a thread of control. @@ -787,7 +815,8 @@ else to the thread. """ - assert group is None, "group argument must be None for now" + if group is not None: + group._add(self) if kwargs is None: kwargs = {} self._target = target