diff --git a/Lib/threading.py b/Lib/threading.py index 94ea2f08178369..744f34653f5476 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -1342,6 +1342,12 @@ def run(self): self.function(*self.args, **self.kwargs) self.finished.set() + def __enter__(self): + self.start() + + def __exit__(self, exc_type, exc_val, exc_tb): + self.cancel() + # Special thread class to represent the main thread