<s> """<STR_LIT>""" <EOL> from multiprocessing import Value <EOL> import tempfile <EOL> import hashlib <EOL> import logging <EOL> import os <EOL> import luigi <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class RunAnywayTarget ( luigi . Target ) : <EOL> """<STR_LIT>""" <EOL> temp_dir = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> temp_time = <NUM_LIT> * <NUM_LIT> <EOL> unique = Value ( '<STR_LIT:i>' , <NUM_LIT:0> ) <EOL> def __init__ ( self , task_obj ) : <EOL> self . task_id = task_obj . task_id <EOL> if self . unique . value == <NUM_LIT:0> : <EOL> with self . unique . get_lock ( ) : <EOL> if self . unique . value == <NUM_LIT:0> : <EOL> self . unique . value = os . getpid ( ) <EOL> if os . path . isdir ( self . temp_dir ) : <EOL> import shutil <EOL> import time <EOL> limit = time . time ( ) - self . temp_time <EOL> for fn in os . listdir ( self . temp_dir ) : <EOL> path = os . path . join ( self . temp_dir , fn ) <EOL> if os . path . isdir ( path ) and os . stat ( path ) . st_mtime < limit : <EOL> shutil . rmtree ( path ) <EOL> logger . debug ( '<STR_LIT>' , path ) <EOL> def get_path ( self ) : <EOL> """<STR_LIT>""" <EOL> md5_hash = hashlib . md5 ( self . task_id . encode ( ) ) . hexdigest ( ) <EOL> logger . debug ( '<STR_LIT>' , md5_hash , self . task_id ) <EOL> return os . path . join ( self . temp_dir , str ( self . unique . value ) , md5_hash ) <EOL> def exists ( self ) : <EOL> """<STR_LIT>""" <EOL> return os . path . isfile ( self . get_path ( ) ) <EOL> def done ( self ) : <EOL> """<STR_LIT>""" <EOL> logger . info ( '<STR_LIT>' , self ) <EOL> fn = self . get_path ( ) <EOL> os . makedirs ( os . path . dirname ( fn ) , exist_ok = True ) <EOL> open ( fn , '<STR_LIT:w>' ) . close ( ) </s>
