projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a simple test to google_assistant code.
[python_utils.git]
/
lockfile.py
diff --git
a/lockfile.py
b/lockfile.py
index 2bbe6f4e2124419bd788312f17a0e6645d921232..290710759dbc702fff757ae2561fe5c0af3051a6 100644
(file)
--- a/
lockfile.py
+++ b/
lockfile.py
@@
-1,27
+1,24
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
-from dataclasses import dataclass
import datetime
import json
import logging
import os
import signal
import sys
import datetime
import json
import logging
import os
import signal
import sys
-from typing import Optional
import warnings
import warnings
+from dataclasses import dataclass
+from typing import Optional
import config
import datetime_utils
import decorator_utils
import config
import datetime_utils
import decorator_utils
-
-cfg = config.add_commandline_args(
- f'Lockfile ({__file__})', 'Args related to lockfiles'
-)
+cfg = config.add_commandline_args(f'Lockfile ({__file__})', 'Args related to lockfiles')
cfg.add_argument(
'--lockfile_held_duration_warning_threshold_sec',
type=float,
cfg.add_argument(
'--lockfile_held_duration_warning_threshold_sec',
type=float,
- default=
1
0.0,
+ default=
6
0.0,
metavar='SECONDS',
help='If a lock is held for longer than this threshold we log a warning',
)
metavar='SECONDS',
help='If a lock is held for longer than this threshold we log a warning',
)
@@
-36,7
+33,7
@@
class LockFileException(Exception):
class LockFileContents:
pid: int
commandline: str
class LockFileContents:
pid: int
commandline: str
- expiration_timestamp:
float
+ expiration_timestamp:
Optional[float]
class LockFile(object):
class LockFile(object):
@@
-132,13
+129,8
@@
class LockFile(object):
if self.locktime:
ts = datetime.datetime.now().timestamp()
duration = ts - self.locktime
if self.locktime:
ts = datetime.datetime.now().timestamp()
duration = ts - self.locktime
- if (
- duration
- >= config.config['lockfile_held_duration_warning_threshold_sec']
- ):
- str_duration = datetime_utils.describe_duration_briefly(
- duration
- )
+ if duration >= config.config['lockfile_held_duration_warning_threshold_sec']:
+ str_duration = datetime_utils.describe_duration_briefly(duration)
msg = f'Held {self.lockfile} for {str_duration}'
logger.warning(msg)
warnings.warn(msg, stacklevel=2)
msg = f'Held {self.lockfile} for {str_duration}'
logger.warning(msg)
warnings.warn(msg, stacklevel=2)
@@
-185,7
+177,7
@@
class LockFile(object):
# Has the lock expiration expired?
if contents.expiration_timestamp is not None:
now = datetime.datetime.now().timestamp()
# Has the lock expiration expired?
if contents.expiration_timestamp is not None:
now = datetime.datetime.now().timestamp()
- if now > contents.expiration_
datetime
:
+ if now > contents.expiration_
timestamp
:
msg = f'Lockfile {self.lockfile} expiration time has passed; force acquiring'
logger.warning(msg)
self.release()
msg = f'Lockfile {self.lockfile} expiration time has passed; force acquiring'
logger.warning(msg)
self.release()