All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
locker Namespace Reference

Classes

class  LockFile
 Lock a file. More...
 

Functions

def lock
 
def unlock
 

Function Documentation

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

Definition at line 16 of file locker.py.

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

Definition at line 34 of file locker.py.

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