remove_event_loop: Allow ignoring specific errors

Replaces a bare except with Exception, and updates the
test case to specify only a single exception that is
allowed to occur.

Related to https://github.com/capnproto/pycapnp/issues/254
This commit is contained in:
John Vandenberg
2021-06-01 16:27:34 +08:00
parent bd91c52d57
commit 4797654323
2 changed files with 28 additions and 7 deletions

View File

@@ -1843,16 +1843,26 @@ cpdef remove_event_loop(ignore_errors=False):
if C_DEFAULT_EVENT_LOOP:
try:
C_DEFAULT_EVENT_LOOP._remove()
except:
if not ignore_errors:
except Exception as e:
if isinstance(ignore_errors, Exception):
if isinstance(e, ignore_errors):
ignore_errors = True
if ignore_errors is True:
pass
else:
raise
C_DEFAULT_EVENT_LOOP = None
if len(_THREAD_LOCAL_EVENT_LOOPS) > 0:
for loop in _THREAD_LOCAL_EVENT_LOOPS:
try:
loop._remove()
except:
if not ignore_errors:
except Exception as e:
if isinstance(ignore_errors, Exception):
if isinstance(e, ignore_errors):
ignore_errors = True
if ignore_errors is True:
pass
else:
raise
_THREAD_LOCAL_EVENT_LOOPS = []
_C_DEFAULT_EVENT_LOOP_LOCAL = None