Skip to content

Commit 7831667

Browse files
+ Bugfix
+ is_alive method
1 parent ae6ad19 commit 7831667

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/thread/thread.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
107107
try:
108108
self.returned_value = target(*args, **kwargs)
109109
except Exception as e:
110-
if type(e) not in self.ignore_errors:
110+
if not any(isinstance(e, ignore) for ignore in self.ignore_errors):
111111
self.status = 'Errored'
112112
self.errors.append(e)
113113
return
@@ -124,7 +124,7 @@ def _invoke_hooks(self) -> None:
124124
try:
125125
hook(self.returned_value)
126126
except Exception as e:
127-
if type(e) not in self.ignore_errors:
127+
if not any(isinstance(e, ignore) for ignore in self.ignore_errors):
128128
trace.add_exception_case(
129129
hook.__name__,
130130
e
@@ -317,6 +317,7 @@ def __init__(
317317
self.overflow_args = overflow_args
318318
self.overflow_kwargs = overflow_kwargs
319319

320+
320321
def _wrap_function(
321322
self,
322323
function: Callable[Concatenate[Data_In, ...], Data_Out]
@@ -353,9 +354,26 @@ def results(self) -> Data_Out:
353354
results: List[Data_Out] = []
354355
for thread in self._threads:
355356
results += thread.result
357+
if thread.status == 'Idle':
358+
raise exceptions.ThreadNotRunningError()
359+
elif thread.status == 'Running':
360+
raise exceptions.ThreadStillRunningError()
356361
return results
357362

358363

364+
def is_alive(self) -> bool:
365+
"""
366+
See if any threads are still alive
367+
368+
Raises
369+
------
370+
ThreadNotInitializedError: If the thread is not intialized
371+
"""
372+
if len(self._threads) == 0:
373+
raise exceptions.ThreadNotInitializedError()
374+
return any(thread.is_alive() for thread in self._threads)
375+
376+
359377
def get_return_values(self) -> List[Data_Out]:
360378
"""
361379
Halts the current thread execution until the thread completes

0 commit comments

Comments
 (0)