diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2024-09-20 02:54:35 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2024-09-20 02:58:07 +0200 |
commit | 45446fcceef55a247d23749a1dcd28417dc73277 (patch) | |
tree | 733717738de164259b0dd25159057bfa9c65412c | |
parent | 287ee168d9879433e356acada20400e63cd9683c (diff) |
webmap-import: add option --lockfile to obtain an exclusive lock.
This avoids starting multiple imports in parallel. Some layers, such as
Skogsstyrelsen's, are quite large and filtering/importing causes rather
high load.
-rwxr-xr-x | webmap-import | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/webmap-import b/webmap-import index 37826cf..bfee9dc 100755 --- a/webmap-import +++ b/webmap-import @@ -18,7 +18,9 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. #---------------------------------------------------------------------- +from os import O_WRONLY, O_CREAT, O_TRUNC, O_CLOEXEC import os +from fcntl import flock, LOCK_EX import logging import argparse import tempfile @@ -1193,6 +1195,8 @@ if __name__ == '__main__': help=f'cache directory (default: {os.curdir})') parser.add_argument('--debug', action='count', default=0, help=argparse.SUPPRESS) + parser.add_argument('--lockfile', default=None, + help=f'obtain an exclusive lock before starting unpacking and importing') parser.add_argument('groupname', nargs='*', help='group layer name(s) to process') args = parser.parse_args() @@ -1244,6 +1248,12 @@ if __name__ == '__main__': srs = getSRS(common.config.get('SRS', None)) extent = getExtent(common.config.get('extent', None), srs=srs) + if args.lockfile is not None: + # obtain an exclusive lock and don't release it until exiting the program + lock_fd = os.open(args.lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, mode=0o644) + logging.debug('flock("%s", LOCK_EX)', args.lockfile) + flock(lock_fd, LOCK_EX) + cachedir = Path(args.cachedir) if args.cachedir is not None else None rv = 0 for layername, layerdef in layers.items(): |