From 882a515caa4101ab009d16de1ef65f7cbcbc9027 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 7 Nov 2012 17:44:55 -0500 Subject: [PATCH] refactored threads which know the user they belong to --- python_apps/media-monitor2/media/saas/thread.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python_apps/media-monitor2/media/saas/thread.py b/python_apps/media-monitor2/media/saas/thread.py index b71c4a8fb..489ad35a8 100644 --- a/python_apps/media-monitor2/media/saas/thread.py +++ b/python_apps/media-monitor2/media/saas/thread.py @@ -2,18 +2,16 @@ import threading tc = threading.local() -class InstanceThread(threading.Thread): +class HasUser(object): + def user(self): + return self._user + +class InstanceThread(threading.Thread, HasUser): def __init__(self,user, *args, **kwargs): super(InstanceThread, self).__init__(*args, **kwargs) self._user = user - - def run(self): - tc._user = self._user - def user(self): - return tc._user - -class InstanceInheritingThread(threading.Thread): +class InstanceInheritingThread(threading.Thread, HasUser): def __init__(self, *args, **kwargs): + self._user = threading.current_thread().user() super(InstanceInheritingThread, self).__init__(*args, **kwargs) - self.user = tc._user