locker Namespace Reference

Classes

class  LockFile
 Lock a file. More...
 

Functions

def lock (file)
 
def unlock (file)
 

Function Documentation

def locker.lock (   file)
Lock first 10 bytes of a file.

Definition at line 16 of file locker.py.

16  def lock(file):
17  """
18  Lock first 10 bytes of a file.
19  """
20  pos = file.tell() # remember current position
21  file.seek(0)
22  # By default, python tries about 10 times, then throws an exception.
23  # We want to wait forever.
24  acquired = False
25  while not acquired:
26  try:
27  msvcrt.locking(file.fileno(),msvcrt.LK_LOCK,10)
28  acquired = True
29  except IOError, x:
30  if x.errno != 36: # 36, AKA 'Resource deadlock avoided', is normal
31  raise
32  file.seek(pos) # reset position
33 
def lock(file)
Definition: locker.py:16
def locker.unlock (   file)
Unlock first 10 bytes of a file.

Definition at line 34 of file locker.py.

34  def unlock(file):
35  """
36  Unlock first 10 bytes of a file.
37  """
38  pos = file.tell() # remember current position
39  file.seek(0)
40  msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
41  file.seek(pos) # reset position
42 
def unlock(file)
Definition: locker.py:34