当前位置: 首页>>代码示例>>Python>>正文


Python Thread.data_set方法代码示例

本文整理汇总了Python中threading.Thread.data_set方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.data_set方法的具体用法?Python Thread.data_set怎么用?Python Thread.data_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading.Thread的用法示例。


在下文中一共展示了Thread.data_set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fetch_query_results

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import data_set [as 别名]
  def fetch_query_results(self, query):
    '''Concurrently execute the query using each cursor and return a list of tuples
       containing the result information for each cursor. The tuple format is
       (<exception or None>, <data set or None>).

       If query_timeout_seconds is reached and the connection is killable then the
       query will be cancelled and the connection reset. Otherwise the query will
       continue to run in the background.

       "query" should be an instance of query.Query.
    '''
    if query.execution != 'RAW':
      self._table_or_view_name = self._create_random_table_name()

    query_threads = list()
    for sql_writer, cursor, log_file \
        in izip(self.sql_writers, self.cursors, self.query_logs):
      if cursor.db_type == IMPALA:
        self.set_impala_query_optons(cursor)
      query_thread = Thread(
          target=self._fetch_sql_results,
          args=[query, cursor, sql_writer, log_file],
          name='Query execution thread {0}'.format(current_thread().name))
      query_thread.daemon = True
      query_thread.sql = ''
      query_thread.data_set = None
      query_thread.cursor_description = None
      query_thread.exception = None
      query_thread.start()
      query_threads.append(query_thread)

    end_time = time() + self.query_timeout_seconds
    for query_thread, cursor in izip(query_threads, self.cursors):
      join_time = end_time - time()
      if join_time > 0:
        query_thread.join(join_time)
      if query_thread.is_alive():
        # Kill connection and reconnect to return cursor to initial state.
        if cursor.conn.supports_kill:
          LOG.debug('Attempting to kill connection')
          cursor.conn.kill()
          LOG.debug('Kill connection')
        try:
          # XXX: Sometimes this takes a very long time causing the program to appear to
          #      hang. Maybe this should be done in another thread so a timeout can be
          #      applied?
          cursor.close()
        except Exception as e:
          LOG.info('Error closing cursor: %s', e)
        cursor.reconnect()
        query_thread.exception = QueryTimeout(
            'Query timed out after %s seconds' % self.query_timeout_seconds)

    return [(query_thread.sql,
        query_thread.exception,
        query_thread.data_set,
        query_thread.cursor_description) for query_thread in query_threads]
开发者ID:ibmsoe,项目名称:ImpalaPPC,代码行数:59,代码来源:discrepancy_searcher.py


注:本文中的threading.Thread.data_set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。