Fix killing greenlets gevent exception
This commit is contained in:
parent
ddbd5c7b19
commit
6bd49e8aff
3 changed files with 15 additions and 5 deletions
|
@ -6,13 +6,19 @@ from Config import config
|
|||
|
||||
# Non fatal exception
|
||||
class Notify(Exception):
|
||||
def __init__(self, message):
|
||||
def __init__(self, message=None):
|
||||
if message:
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
|
||||
# Gevent greenlet.kill accept Exception type
|
||||
def createNotifyType(message):
|
||||
return type("Notify", (Notify, ), {"message": message})
|
||||
|
||||
|
||||
def formatExceptionMessage(err):
|
||||
err_type = err.__class__.__name__
|
||||
if err.args:
|
||||
|
@ -101,6 +107,8 @@ import time
|
|||
|
||||
|
||||
num_block = 0
|
||||
|
||||
|
||||
def testBlock():
|
||||
global num_block
|
||||
logging.debug("Gevent block checker started")
|
||||
|
@ -111,6 +119,8 @@ def testBlock():
|
|||
logging.debug("Gevent block detected: %.3fs" % (time.time() - last_time - 1))
|
||||
num_block += 1
|
||||
last_time = time.time()
|
||||
|
||||
|
||||
gevent.spawn(testBlock)
|
||||
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ class Worker(object):
|
|||
def skip(self, reason="Unknown"):
|
||||
self.manager.log.debug("%s: Force skipping (reason: %s)" % (self.key, reason))
|
||||
if self.thread:
|
||||
self.thread.kill(exception=Debug.Notify("Worker skipping (reason: %s)" % reason))
|
||||
self.thread.kill(exception=Debug.createNotifyType("Worker skipping (reason: %s)" % reason))
|
||||
self.start()
|
||||
|
||||
# Force stop the worker
|
||||
|
@ -234,6 +234,6 @@ class Worker(object):
|
|||
self.manager.log.debug("%s: Force stopping (reason: %s)" % (self.key, reason))
|
||||
self.running = False
|
||||
if self.thread:
|
||||
self.thread.kill(exception=Debug.Notify("Worker stopped (reason: %s)" % reason))
|
||||
self.thread.kill(exception=Debug.createNotifyType("Worker stopped (reason: %s)" % reason))
|
||||
del self.thread
|
||||
self.manager.removeWorker(self)
|
||||
|
|
|
@ -20,5 +20,5 @@ class GreenletManager:
|
|||
|
||||
def stopGreenlets(self, reason="Stopping all greenlets"):
|
||||
num = len(self.greenlets)
|
||||
gevent.killall(list(self.greenlets), Debug.Notify(reason), block=False)
|
||||
gevent.killall(list(self.greenlets), Debug.createNotifyType(reason), block=False)
|
||||
return num
|
||||
|
|
Loading…
Reference in a new issue