Skip to content

Commit 8ca9c94

Browse files
committed
Handle task kill status in try-except block
1 parent c607067 commit 8ca9c94

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

labthings/core/tasks/thread.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from gevent import Greenlet
1+
from gevent import Greenlet, GreenletExit
22
import datetime
33
import logging
44
import traceback
@@ -88,6 +88,11 @@ def wrapped(*args, **kwargs):
8888
try:
8989
self._return_value = f(*args, **kwargs)
9090
self._status = "success"
91+
except (TaskKillException, GreenletExit) as e:
92+
logging.error(e)
93+
# Set state to terminated
94+
self._status = "terminated"
95+
self.progress = None
9196
except Exception as e: # skipcq: PYL-W0703
9297
logging.error(e)
9398
logging.error(traceback.format_exc())
@@ -101,9 +106,6 @@ def wrapped(*args, **kwargs):
101106
def kill(self, exception=TaskKillException, block=True, timeout=None):
102107
# Kill the greenlet
103108
Greenlet.kill(self, exception=exception, block=block, timeout=timeout)
104-
# Set state to terminated
105-
self._status = "terminated"
106-
self.progress = None
107109

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

0 commit comments

Comments
 (0)