From f5f85c661cb8585eda9f4abb4ba455e11d4f0fb3 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 8 Aug 2014 11:08:18 +0400 Subject: [PATCH 1/3] get script name from module string --- mmc/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmc/mixins.py b/mmc/mixins.py index 663aa01..61a2f7b 100644 --- a/mmc/mixins.py +++ b/mmc/mixins.py @@ -31,7 +31,7 @@ def __init__(self): self._error_message = None self._traceback = None self._show_traceback = False - self._script = sys.argv[1] + self._script = self.__module__.split('.')[-1] self._lock = get_lock_instance() def __mmc_one_copy(self): From 69db6d86e5bed8149199d0bd85415909c4e053e3 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 8 Aug 2014 11:44:10 +0400 Subject: [PATCH 2/3] raise command exception --- mmc/mixins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mmc/mixins.py b/mmc/mixins.py index 61a2f7b..864f6d8 100644 --- a/mmc/mixins.py +++ b/mmc/mixins.py @@ -54,10 +54,11 @@ def execute(self, *args, **options): try: self._no_monkey.execute(self, *args, **options) - except Exception, ex: + except Exception as ex: self._success = False self._error_message = ex.__unicode__() self._traceback = traceback.format_exc() + raise def __mmc_store_log(self): try: From d4ef54c770a5ef108997995786be02fbbcc3e840 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 8 Aug 2014 12:17:39 +0400 Subject: [PATCH 3/3] pass 'script' argument to get_lock_instance --- mmc/lock.py | 16 ++++++++-------- mmc/mixins.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mmc/lock.py b/mmc/lock.py index 49a5646..8db0045 100644 --- a/mmc/lock.py +++ b/mmc/lock.py @@ -10,9 +10,9 @@ class AbstractLock(object): - def __init__(self): + def __init__(self, script): + self._script = script self._tempdir = tempfile.gettempdir() - self._script = sys.argv[1] def get_lock_file(self): return os.path.join(self._tempdir, self._script + '.lock') @@ -50,11 +50,11 @@ def is_run(self): class RedisLock(AbstractLock): - def __init__(self): + def __init__(self, script): from redis import StrictRedis self._cli = StrictRedis(**defaults.REDIS_CONFIG) - super(RedisLock, self).__init__() + super(RedisLock, self).__init__(script) self.random_wait() def unlock(self): @@ -69,16 +69,16 @@ def is_run(self): class MemcacheLock(RedisLock): - def __init__(self): + def __init__(self, script): try: from memcache import Client except ImportError: from pylibmc import Client - super(MemcacheLock, self).__init__() + super(MemcacheLock, self).__init__(script) self._cli = Client(**defaults.MEMCACHED_CONFIG) self.random_wait() -def get_lock_instance(): - return globals().get(defaults.LOCK_TYPE)() +def get_lock_instance(script): + return globals().get(defaults.LOCK_TYPE)(script) diff --git a/mmc/mixins.py b/mmc/mixins.py index 864f6d8..10512be 100644 --- a/mmc/mixins.py +++ b/mmc/mixins.py @@ -32,7 +32,7 @@ def __init__(self): self._traceback = None self._show_traceback = False self._script = self.__module__.split('.')[-1] - self._lock = get_lock_instance() + self._lock = get_lock_instance(self._script) def __mmc_one_copy(self): try: