<commit_before># Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Thread and ThreadGroup that reraise exceptions on the main thread."""
# pylint: disable=W0212

import logging
import sys
import threading
import time
import traceback

from devil.utils import watchdog_timer


class TimeoutError(Exception):
  """Module-specific timeout exception."""
  pass


def LogThreadStack(thread, error_log_func=logging.critical):
  """Log the stack for the given thread.

  Args:
    thread: a threading.Thread instance.
    error_log_func: Logging function when logging errors.
  """
  stack = sys._current_frames()[thread.ident]
  error_log_func('*' * 80)
  error_log_func('Stack dump for thread %r', thread.name)
  error_log_func('*' * 80)
  for filename, lineno, name, line in traceback.extract_stack(stack):
    error_log_func('File: "%s", line %d, in %s', filename, lineno, name)
    if line:
      error_log_func('  %s', line.strip())
  error_log_func('*' * 80)


class ReraiserThread(threading.Thread):
  """Thread class that can reraise exceptions."""

  def __init__(self, func, args=None, kwargs=None, name=None):
    """Initialize thread.

    Args:
      func: callable to call on a new thread.
      args: list of positional arguments for callable, defaults to empty.
      kwargs: dictionary of keyword arguments for callable, defaults to empty.
      name: thread name, defaults to Thread-N.
    """
    super(ReraiserThread, self).__init__(name=name)
    if not args:
      args = []
    if not kwargs:<commit_msg>reraiser_thread: Use func.__name__ for thread names<commit_after># Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Thread and ThreadGroup that reraise exceptions on the main thread."""
# pylint: disable=W0212

import logging
import sys
import threading
import time
import traceback

from devil.utils import watchdog_timer


class TimeoutError(Exception):
  """Module-specific timeout exception."""
  pass


def LogThreadStack(thread, error_log_func=logging.critical):
  """Log the stack for the given thread.

  Args:
    thread: a threading.Thread instance.
    error_log_func: Logging function when logging errors.
  """
  stack = sys._current_frames()[thread.ident]
  error_log_func('*' * 80)
  error_log_func('Stack dump for thread %r', thread.name)
  error_log_func('*' * 80)
  for filename, lineno, name, line in traceback.extract_stack(stack):
    error_log_func('File: "%s", line %d, in %s', filename, lineno, name)
    if line:
      error_log_func('  %s', line.strip())
  error_log_func('*' * 80)


class ReraiserThread(threading.Thread):
  """Thread class that can reraise exceptions."""

  def __init__(self, func, args=None, kwargs=None, name=None):
    """Initialize thread.

    Args:
      func: callable to call on a new thread.
      args: list of positional arguments for callable, defaults to empty.
      kwargs: dictionary of keyword arguments for callable, defaults to empty.
      name: thread name, defaults to Thread-N.
    """
    if not name and func.__name__ != '<lambda>':
      name = func.__name__
    super(ReraiserThread, self).__init__(name=name)
    if not args:
      args = []
    if not kwargs:
{'fraction_non_alphanumeric': 0.10283687943262411, 'fraction_numerical': 0.008274231678486997, 'mean_word_length': 3.9416058394160585, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347494', 'n_tokens_mistral': 1046, 'n_tokens_neox': 999, 'n_words': 364}