def _enable_thread_pool(func):
@functools.wraps(func)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>self = args[<NUM_LIT:0>]<EOL>if self.enable_thread_pool and hasattr(self, '<STR_LIT>'):<EOL><INDENT>future = self.thread_pool.submit(func, *args, **kwargs)<EOL>is_async = kwargs.get('<STR_LIT>')<EOL>if is_async is None or not is_async:<EOL><INDENT>timeout = kwargs.get('<STR_LIT>')<EOL>if timeout is None:<EOL><INDENT>timeout = <NUM_LIT:2><EOL><DEDENT>try:<EOL><INDENT>result = future.result(timeout=timeout)<EOL><DEDENT>except TimeoutError as e:<EOL><INDENT>self.logger.exception(e)<EOL>result = None<EOL><DEDENT>return result<EOL><DEDENT>return future<EOL><DEDENT>else:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT><DEDENT>return wrapper<EOL>
Use thread pool for executing a task if self.enable_thread_pool is True.

Return an instance of future when flag is_async is True otherwise will to
block waiting for the result until timeout then returns the result.