source: people/peter.buschman/backup_monitoring/backmon/lib/locking.py@ 1273

Last change on this file since 1273 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 757 bytes
Line 
1###
2### backmon.lib.locking
3###
4import os
5import os.path
6import time
7
8from .exceptions import BackmonError
9
10#
11# lock() - Lock a file using lock directory semantics
12#
13def lock(path, retries=1, sleep=1):
14
15 lock_dir = '%s.lock' % (path)
16
17 for i in range(retries):
18 try:
19 os.mkdir(lock_dir)
20 return True
21 except OSError:
22 time.sleep(sleep)
23
24 return False
25
26
27#
28# unlock() - Unlock a file using lock directory semantics
29#
30def unlock(path, retries=1, sleep=1):
31
32 lock_dir = '%s.lock' % (path)
33
34 for i in range(retries):
35 try:
36 os.rmdir(lock_dir)
37 return True
38 except OSError:
39 time.sleep(sleep)
40
41 return False
42
Note: See TracBrowser for help on using the repository browser.