From 5ea881a31173380e10ffdd6b05c02f92d9177f04 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 1 Nov 2012 10:29:42 +1100 Subject: Don't log exceptions for GreenletExit and thread_done 1) Greenletexit is normal so don't log it. 2) logging in a linked callback is just asking for problems. (we don't want to cause a context switch in this callback). Change-Id: Ia9bb1cabc65a742fc49beb379548eb680b326e58 --- openstack/common/threadgroup.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'openstack') diff --git a/openstack/common/threadgroup.py b/openstack/common/threadgroup.py index ebc066a..9d2f0b6 100644 --- a/openstack/common/threadgroup.py +++ b/openstack/common/threadgroup.py @@ -13,10 +13,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os -import sys -from eventlet import event +from eventlet import greenlet from eventlet import greenpool from eventlet import greenthread @@ -29,7 +27,11 @@ LOG = logging.getLogger(__name__) def _thread_done(gt, *args, **kwargs): - args[0].thread_done(args[1]) + ''' + Callback function to be passed to GreenThread.link() when we spawn() + Calls the ThreadGroup to notify if. + ''' + kwargs['group'].thread_done(kwargs['thread']) class Thread(object): @@ -42,7 +44,7 @@ class Thread(object): def __init__(self, name, thread, group): self.name = name self.thread = thread - self.thread.link(_thread_done, group, self) + self.thread.link(_thread_done, group=group, thread=self) def stop(self): self.thread.cancel() @@ -77,12 +79,7 @@ class ThreadGroup(): self.threads.append(th) def thread_done(self, thread): - try: - thread.wait() - except Exception as ex: - LOG.exception(ex) - finally: - self.threads.remove(thread) + self.threads.remove(thread) def stop(self): current = greenthread.getcurrent() @@ -106,6 +103,8 @@ class ThreadGroup(): for x in self.timers: try: x.wait() + except greenlet.GreenletExit: + pass except Exception as ex: LOG.exception(ex) current = greenthread.getcurrent() @@ -114,5 +113,7 @@ class ThreadGroup(): continue try: x.wait() + except greenlet.GreenletExit: + pass except Exception as ex: LOG.exception(ex) -- cgit