tests: add a Thread class that catches exceptions

This commit is contained in:
Robert Vollmert
2022-08-02 19:03:45 +02:00
committed by Robert
parent 70cae5beed
commit b6a93aae1f
+20
View File
@@ -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."