From a08ca309cb5bd7971210a9247a38c9bbe376a6e6 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Thu, 29 Jul 2021 09:11:05 -0700 Subject: [PATCH] Lockfile custom command, fixup minor things. --- decorator_utils.py | 2 +- lockfile.py | 10 ++++++++-- type/centcount.py | 2 +- type/money.py | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/decorator_utils.py b/decorator_utils.py index 0d5b3e3..76faec6 100644 --- a/decorator_utils.py +++ b/decorator_utils.py @@ -340,7 +340,7 @@ def _target(queue, function, *args, **kwargs): """ try: queue.put((True, function(*args, **kwargs))) - except: + except Exception: queue.put((False, sys.exc_info()[1])) diff --git a/lockfile.py b/lockfile.py index ee8c255..770beaa 100644 --- a/lockfile.py +++ b/lockfile.py @@ -37,9 +37,11 @@ class LockFile(object): *, do_signal_cleanup: bool = True, expiration_timestamp: Optional[float] = None, + override_command: Optional[str] = None, ) -> None: self.is_locked = False self.lockfile = lockfile_path + self.override_command = override_command if do_signal_cleanup: signal.signal(signal.SIGINT, self._signal) signal.signal(signal.SIGTERM, self._signal) @@ -117,10 +119,14 @@ class LockFile(object): self.release() def _get_lockfile_contents(self) -> str: + if self.override_command: + cmd = self.override_command + else: + cmd = ' '.join(sys.argv) contents = LockFileContents( pid = os.getpid(), - commandline = ' '.join(sys.argv), - expiration_timestamp = self.expiration_timestamp + cmd, + expiration_timestamp = self.expiration_timestamp, ) return json.dumps(contents.__dict__) diff --git a/type/centcount.py b/type/centcount.py index 4181721..ce18975 100644 --- a/type/centcount.py +++ b/type/centcount.py @@ -210,7 +210,7 @@ class CentCount(object): centcount = int(float(chunk) * 100.0) elif CentCount.CURRENCY_RE.match(chunk) is not None: currency = chunk - except: + except Exception: pass if centcount is not None and currency is not None: return (centcount, currency) diff --git a/type/money.py b/type/money.py index c77a938..290c2c8 100644 --- a/type/money.py +++ b/type/money.py @@ -17,7 +17,7 @@ class Money(object): def __init__ ( self, - amount: Decimal = Decimal("0.0"), + amount: Decimal = Decimal("0"), currency: str = 'USD', *, strict_mode = False @@ -211,7 +211,7 @@ class Money(object): amount = Decimal(chunk) elif Money.CURRENCY_RE.match(chunk) is not None: currency = chunk - except: + except Exception: pass if amount is not None and currency is not None: return (amount, currency) -- 2.45.2