<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import time <EOL> from conda . exceptions import LockError <EOL> LOCKFN = '<STR_LIT>' <EOL> stdoutlog = logging . getLogger ( '<STR_LIT>' ) <EOL> class Locked ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , path , retries = <NUM_LIT:10> ) : <EOL> self . path = path <EOL> self . end = "<STR_LIT:->" + str ( os . getpid ( ) ) <EOL> self . lock_path = os . path . join ( self . path , LOCKFN + self . end ) <EOL> self . retries = retries <EOL> def __enter__ ( self ) : <EOL> lockstr = ( """<STR_LIT>""" ) <EOL> sleeptime = <NUM_LIT:1> <EOL> for _ in range ( self . retries ) : <EOL> if os . path . isdir ( self . lock_path ) : <EOL> stdoutlog . info ( lockstr % self . lock_path ) <EOL> stdoutlog . info ( "<STR_LIT>" % sleeptime ) <EOL> time . sleep ( sleeptime ) <EOL> sleeptime *= <NUM_LIT:2> <EOL> else : <EOL> os . makedirs ( self . lock_path ) <EOL> return self <EOL> stdoutlog . error ( "<STR_LIT>" ) <EOL> raise LockError ( lockstr % self . lock_path ) <EOL> def __exit__ ( self , exc_type , exc_value , traceback ) : <EOL> try : <EOL> os . rmdir ( self . lock_path ) <EOL> os . rmdir ( self . path ) <EOL> except OSError : <EOL> pass </s>
