3232@author: Andy Georges (Ghent University)
3333"""
3434import errno
35+ import logging
3536import os
3637import signal
3738import time
3839
3940from lockfile .linklockfile import LockBase , LockFailed , NotLocked , NotMyLock
40-
41- from vsc .utils import fancylogger
42-
41+ from vsc .utils .py2vs3 import FileNotFoundErrorExc , FileExistsErrorExc
4342
4443class LockFileReadError (Exception ):
4544 '''Exception raised when we cannot get the expected information from the lock file.'''
@@ -54,7 +53,6 @@ def __init__(self, path, threshold=60):
5453 '''Intializer.'''
5554 LockBase .__init__ (self , path , False )
5655 self .threshold = threshold
57- self .logger = fancylogger .getLogger (self .__class__ .__name__ )
5856
5957 def read_pid_timestamp (self ):
6058 '''Obtain the PID and timestamp from the lockfile.
@@ -84,24 +82,24 @@ def acquire(self, timeout=None):
8482 timeout = self .threshold
8583 try :
8684 _write_pid_timestamp_file (self .path )
87- self . logger .info ('Obtained lock on timestamped pid lockfile %s' , self .path )
88- except OSError as err :
85+ logging .info ('Obtained lock on timestamped pid lockfile %s' , self .path )
86+ except ( OSError , FileNotFoundErrorExc , FileExistsErrorExc ) as err :
8987 doraise = True
9088 if err .errno == errno .EEXIST :
9189 ## Check if the timestamp is older than the threshold
9290 (pid , timestamp ) = _read_pid_timestamp_file (self .path )
9391 if time .time () - timestamp > timeout :
9492 _find_and_kill (pid )
9593 os .unlink (self .path )
96- self . logger .warning ('Obsolete lockfile detected at %s: pid = %d, timestamp = %s' ,
97- self .path , pid , time .ctime (timestamp ))
94+ logging .warning ('Obsolete lockfile detected at %s: pid = %d, timestamp = %s' ,
95+ self .path , pid , time .ctime (timestamp ))
9896 try :
9997 _write_pid_timestamp_file (self .path )
10098 doraise = False
10199 except Exception :
102100 pass
103101 if doraise :
104- self . logger .error ('Unable to obtain lock on %s: %s' , self .path , err )
102+ logging .error ('Unable to obtain lock on %s: %s' , self .path , err )
105103 raise LockFailed
106104
107105 def release (self ):
@@ -110,10 +108,10 @@ def release(self):
110108 Remove the lockfile to indicate the lock was released.
111109 '''
112110 if not self .is_locked ():
113- self . logger .error ('Trying to release a lock that does not exist at %s.' , self .path )
111+ logging .error ('Trying to release a lock that does not exist at %s.' , self .path )
114112 raise NotLocked
115113 if not self .i_am_locking ():
116- self . logger .error ('Trying to release a lock the current process is not holding at %s' , self .path )
114+ logging .error ('Trying to release a lock the current process is not holding at %s' , self .path )
117115 raise NotMyLock
118116 os .remove (self .path )
119117
0 commit comments