Skip to content

Commit

Permalink
Simplified thread run method
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jul 22, 2020
1 parent 3117b74 commit 0656200
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/labthings/actions/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ def run(self):
"""Overrides default threading.Thread run() method"""
logging.debug((self._args, self._kwargs))
try:
with self._running_lock:
# Don't run if the thread was stopped before starting
if self.stopping.is_set():
raise ActionKilledException
if self._target:
if self._target:
with self._running_lock:
self._thread_proc(self._target)(*self._args, **self._kwargs)
finally:
# Avoid a refcycle if the thread is running a function with
Expand Down Expand Up @@ -279,15 +276,9 @@ def terminate(self, exception=ActionKilledException):
"""
_LOG.warning(f"Terminating thread {self}")
if not self.is_alive():
if not (self.is_alive() or self._is_thread_proc_running()):
logging.debug("Cannot kill thread that is no longer running.")
return
if not self._is_thread_proc_running():
logging.debug(
"Thread's _thread_proc function is no longer running, "
"will not kill; letting thread exit gracefully."
)
return
return False
self._async_raise(exception)

# Wait (block) for the thread to finish closing. If the threaded function has cleanup code in a try-except,
Expand Down

0 comments on commit 0656200

Please sign in to comment.