Functions | |
def | lock |
def | unlock |
def | _tmpFileName |
def | _lckFileName |
def | _linkCount |
def | _read |
def | _sleep |
Variables | |
LOCK_EX = fcntl.F_WRLCK | |
LOCK_SH = fcntl.F_RDLCK | |
LOCK_NB = fcntl.F_UNLCK |
def fragments::locker::lock | ( | file | ) |
Lock first 10 bytes of a file.
Definition at line 19 of file locker.py.
00019 : 00020 """ 00021 Lock first 10 bytes of a file. 00022 """ 00023 pos = file.tell() # remember current position 00024 file.seek(0) 00025 # By default, python tries about 10 times, then throws an exception. 00026 # We want to wait forever. 00027 acquired = False 00028 while not acquired: 00029 try: 00030 msvcrt.locking(file.fileno(),msvcrt.LK_LOCK,10) 00031 acquired = True 00032 except IOError, x: 00033 if x.errno != 36: # 36, AKA 'Resource deadlock avoided', is normal 00034 raise 00035 file.seek(pos) # reset position 00036 def unlock(file):
def fragments::locker::unlock | ( | file | ) |
Unlock first 10 bytes of a file.
Definition at line 37 of file locker.py.
00037 : 00038 """ 00039 Unlock first 10 bytes of a file. 00040 """ 00041 pos = file.tell() # remember current position 00042 file.seek(0) 00043 msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10) 00044 file.seek(pos) # reset position 00045 elif os.name =='posix':
def fragments::locker::_tmpFileName | ( | fileName | ) | [private] |
Definition at line 49 of file locker.py.
00049 : 00050 return "%s.%s.%d" % ( fileName, socket.gethostname(), os.getpid() ) def _lckFileName(fileName):
def fragments::locker::_lckFileName | ( | fileName | ) | [private] |
Definition at line 51 of file locker.py.
00051 : 00052 return "%s.lock" % fileName 00053 def _linkCount( lockFileName ):
def fragments::locker::_linkCount | ( | lockFileName | ) | [private] |
def fragments::locker::_read | ( | fileName | ) | [private] |
Definition at line 61 of file locker.py.
00061 : 00062 try: 00063 fp = open(fileName) 00064 try: readFileName = fp.read() 00065 finally: fp.close() 00066 return readFileName 00067 except EnvironmentError, e: 00068 if e.errno != errno.ENOENT: 00069 raise 00070 return None 00071 def _sleep(): time.sleep(8)
def fragments::locker::_sleep | ( | ) | [private] |
fragments::locker::LOCK_EX = fcntl.F_WRLCK [static] |
fragments::locker::LOCK_SH = fcntl.F_RDLCK [static] |
fragments::locker::LOCK_NB = fcntl.F_UNLCK [static] |