<s> import fcntl <EOL> import os <EOL> MNTPT = '<STR_LIT>' <EOL> class MountLock : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , blocking = True , mntpt = MNTPT ) : <EOL> self . _fd = os . open ( mntpt , os . O_DIRECTORY ) <EOL> flags = fcntl . FD_CLOEXEC | fcntl . fcntl ( self . _fd , fcntl . F_GETFL ) <EOL> fcntl . fcntl ( self . _fd , fcntl . F_SETFL , flags ) <EOL> if blocking : <EOL> self . __enter__ = self . lock <EOL> else : <EOL> self . __enter__ = self . lock_try <EOL> def __del__ ( self ) : <EOL> if self . _fd : <EOL> os . close ( self . _fd ) <EOL> def __exit__ ( self , exc_type , value , traceback ) : <EOL> self . unlock ( ) <EOL> def lock_try ( self ) : <EOL> """<STR_LIT>""" <EOL> fcntl . flock ( self . _fd , fcntl . LOCK_EX | fcntl . LOCK_NB ) <EOL> def lock ( self ) : <EOL> """<STR_LIT>""" <EOL> fcntl . flock ( self . _fd , fcntl . LOCK_EX ) <EOL> def unlock ( self ) : <EOL> """<STR_LIT>""" <EOL> fcntl . flock ( self . _fd , fcntl . LOCK_UN ) <EOL> mntlock = MountLock </s>
