Skip to content

Commit

Permalink
Handle task kill status in try-except block
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed Mar 31, 2020
1 parent c607067 commit 8ca9c94
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions labthings/core/tasks/thread.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gevent import Greenlet
from gevent import Greenlet, GreenletExit
import datetime
import logging
import traceback
Expand Down Expand Up @@ -88,6 +88,11 @@ def wrapped(*args, **kwargs):
try:
self._return_value = f(*args, **kwargs)
self._status = "success"
except (TaskKillException, GreenletExit) as e:
logging.error(e)
# Set state to terminated
self._status = "terminated"
self.progress = None
except Exception as e: # skipcq: PYL-W0703
logging.error(e)
logging.error(traceback.format_exc())
Expand All @@ -101,9 +106,6 @@ def wrapped(*args, **kwargs):
def kill(self, exception=TaskKillException, block=True, timeout=None):
# Kill the greenlet
Greenlet.kill(self, exception=exception, block=block, timeout=timeout)
# Set state to terminated
self._status = "terminated"
self.progress = None

def terminate(self):
return self.kill()

0 comments on commit 8ca9c94

Please sign in to comment.