def close(block=True, timeout=3):
        ''' @param block: if True, block the caller until the thread 
                          is closed or time out
            @param timout: if blocked, timeout is used
            @return: if block, True -> close successfully; False -> timeout
                     if non block, always return False
        '''
        if not block:
            cancelled.set()
            return False
        else:
            cancelled.set()
            th.join(timeout)
            isClosed = not th.isAlive()
            return isClosed
 @param block: if True, block the caller until the thread 
                          is closed or time out
            @param timout: if blocked, timeout is used
            @return: if block, True -> close successfully; False -> timeout
                     if non block, always return False
        
recipes/Python/576726_Interval_Execute_a_function/recipe-576726.py