diff options
author | Andy Doan <andy.doan@linaro.org> | 2016-01-20 13:40:42 -0600 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2016-01-20 15:00:43 -0600 |
commit | 674b48c95bf57c883cda4c6f405c28ce789387f5 (patch) | |
tree | 886d238fc6b9c0afb42d426f5d038915820d5ee3 /update_commited_patches.py | |
parent | 7bb7eae80c89ac8a1c644796d393228c18038bd1 (diff) |
Ensure only one instance of update_commited_patches runs at a time
I saw a problem where the script hung, then other copies came along and
things just cascaded. This is a simple hack to exit with an error if the
script is already running.
Change-Id: I7eeb5e072f69c93e5e1d6b4ef6e0c6126ca4cb0c
Diffstat (limited to 'update_commited_patches.py')
-rwxr-xr-x | update_commited_patches.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/update_commited_patches.py b/update_commited_patches.py index d930fef..633eccf 100755 --- a/update_commited_patches.py +++ b/update_commited_patches.py @@ -1,8 +1,10 @@ #!/usr/bin/python +import fcntl import logging import os import operator +import sys from bin import django_setup, add_logging_arguments django_setup() # must be called to get sys.path and django settings in place @@ -76,6 +78,13 @@ if __name__ == '__main__': _assert_repo_dir(settings.REPO_DIR) + # Ensure no other copy of this script is running + f = open(os.path.join(settings.REPO_DIR, '.lock'), 'w+') + try: + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError: + sys.exit('Script is already running') + if args.project: projects = [Project.objects.get(linkname=args.project)] else: |