<s> import sys <EOL> import threading <EOL> from System . Threading import Thread , ThreadStart <EOL> from robot . errors import TimeoutError <EOL> class Timeout ( object ) : <EOL> def __init__ ( self , timeout , error ) : <EOL> self . _timeout = timeout <EOL> self . _error = error <EOL> def execute ( self , runnable ) : <EOL> runner = Runner ( runnable ) <EOL> thread = Thread ( ThreadStart ( runner ) ) <EOL> thread . IsBackground = True <EOL> thread . Start ( ) <EOL> if not thread . Join ( self . _timeout * <NUM_LIT:1000> ) : <EOL> thread . Abort ( ) <EOL> raise TimeoutError ( self . _error ) <EOL> return runner . get_result ( ) <EOL> class Runner ( object ) : <EOL> def __init__ ( self , runnable ) : <EOL> self . _runnable = runnable <EOL> self . _result = None <EOL> self . _error = None <EOL> def __call__ ( self ) : <EOL> threading . currentThread ( ) . setName ( '<STR_LIT>' ) <EOL> try : <EOL> self . _result = self . _runnable ( ) <EOL> except : <EOL> self . _error = sys . exc_info ( ) <EOL> def get_result ( self ) : <EOL> if not self . _error : <EOL> return self . _result <EOL> raise self . _error [ <NUM_LIT:0> ] , self . _error [ <NUM_LIT:1> ] , self . _error [ <NUM_LIT:2> ] </s>
