tests: add a Thread class that catches exceptions
This commit is contained in:
@@ -13,6 +13,7 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
@@ -46,6 +47,25 @@ def itemgetter(*items):
|
|||||||
return g
|
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):
|
class PostgrestTimedOut(Exception):
|
||||||
"Connecting to PostgREST endpoint timed out."
|
"Connecting to PostgREST endpoint timed out."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user