diff --git a/test/io/test_io.py b/test/io/test_io.py index b6cde1f7b..feda74f79 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -13,6 +13,7 @@ import signal import socket import subprocess import tempfile +import threading import time import urllib.parse @@ -46,6 +47,25 @@ def itemgetter(*items): return g +class Thread(threading.Thread): + "Variant of threading.Thread that re-raises any exceptions when joining the thread" + + def __init__(self, *args, **kwargs): + self._exception = None + super(Thread, self).__init__(*args, **kwargs) + + def run(self): + try: + super(Thread, self).run() + except Exception as e: + self._exception = e + + def join(self): + super(Thread, self).join() + if self._exception is not None: + raise self._exception + + class PostgrestTimedOut(Exception): "Connecting to PostgREST endpoint timed out."