@@ -42,8 +42,8 @@ class BaseLock(object):
4242 """Base class for file locking
4343 """
4444
45- def __init__ (self , fd ):
46- self .fd = fd
45+ def __init__ (self , fileobj ):
46+ self .fileobj = fileobj
4747 self .locked = False
4848
4949 def acquire (self ):
@@ -69,39 +69,39 @@ class UnixFileLock(BaseLock):
6969 """Simple file locking for Unix using fcntl
7070 """
7171
72- def __init__ (self , fd , mode = None ):
73- super (UnixFileLock , self ).__init__ (fd )
72+ def __init__ (self , fileobj , mode = None ):
73+ super (UnixFileLock , self ).__init__ (fileobj )
7474
7575 if mode is None :
7676 mode = fcntl .LOCK_EX
7777 self .mode = mode
7878
7979 def acquire (self ):
8080 try :
81- fcntl .flock (self .fd , self .mode )
81+ fcntl .flock (self .fileobj , self .mode )
8282 self .locked = True
8383 except IOError as e :
8484 if e .errno != errno .ENOLCK :
8585 raise e
8686
8787 def release (self ):
88- fcntl .flock (self .fd , fcntl .LOCK_UN )
88+ fcntl .flock (self .fileobj , fcntl .LOCK_UN )
8989 self .locked = False
9090
9191
9292class WindowsFileLock (BaseLock ):
9393 """Simple file locking for Windows using msvcrt
9494 """
9595
96- def __init__ (self , fd , mode = None ):
97- super (WindowsFileLock , self ).__init__ (fd )
96+ def __init__ (self , fileobj , mode = None ):
97+ super (WindowsFileLock , self ).__init__ (fileobj )
9898
9999 def acquire (self ):
100- msvcrt .locking (self .fd , msvcrt .LK_NBLCK , 1 )
100+ msvcrt .locking (self .fileobj . fileno () , msvcrt .LK_NBLCK , 1 )
101101 self .locked = True
102102
103103 def release (self ):
104- msvcrt .locking (self .fd , msvcrt .LK_UNLCK , 1 )
104+ msvcrt .locking (self .fileobj . fileno () , msvcrt .LK_UNLCK , 1 )
105105 self .locked = False
106106
107107
0 commit comments