]> TLD Linux GIT Repositories - TLD.git/blob - pld-builder.new/PLD_Builder/lock.py
942cce51426136531252bc99c67dce9138c574f0
[TLD.git] / pld-builder.new / PLD_Builder / lock.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import fcntl
4
5 import path
6
7 locks_list = []
8
9 def lock(n, non_block = 0):
10     f = open(path.lock_dir + '/' + n, "a")
11     # blah, otherwise it gets garbage collected and doesn't work
12     locks_list.append(f)
13     if non_block:
14         try:
15             fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
16         except:
17             f.close()
18             return None
19     else:
20         fcntl.flock(f, fcntl.LOCK_EX)
21     return f