tools/perf/core/results_processor/util.py
def ApplyInParallel(function, work_list, on_failure=None):
  """Apply a function to all values in work_list in parallel.

  Args:
    function: A function with one argument.
    work_list: Any iterable with arguments for the function.
    on_failure: A function to run in case of a failure.
  """
  if not work_list:
    return

  try:
    # Note that this is speculatively halved as an attempt to fix
    # crbug.com/953365.
    cpu_count = multiprocessing.cpu_count() // 2
    if sys.platform == 'win32':
      # TODO(crbug.com/1190269) - we can't use more than 56
      # cores on Windows or Python3 may hang.
      cpu_count = min(cpu_count, 56)

  except NotImplementedError:
    # Some platforms can raise a NotImplementedError from cpu_count()
    logging.warning('cpu_count() not implemented.')
    cpu_count = 4
  pool = ThreadPool(min(cpu_count, len(work_list)))

  def function_with_try(arg):
    try:
      function(arg)
    except Exception:  # pylint: disable=broad-except
      # logging exception here is the only way to get a stack trace since
      # multiprocessing's pool implementation does not save that data. See
      # crbug.com/953365.
      logging.exception('Exception while running %s' % function.__name__)
      if on_failure:
        on_failure(arg)

  try:
    pool.imap_unordered(function_with_try, work_list)
    pool.close()
    pool.join()
  finally:
    pool.terminate()
Apply a function to all values in work_list in parallel.

  Args:
    function: A function with one argument.
    work_list: Any iterable with arguments for the function.
    on_failure: A function to run in case of a failure.
  
Apply a function to all values in work_list in parallel.
Apply a function to all values in work_list in parallel .
def ApplyInParallel(function, work_list, on_failure=None):
  if not work_list:
    return
  try:
    cpu_count = multiprocessing.cpu_count() // 2
    if sys.platform == 'win32':
      cpu_count = min(cpu_count, 56)
  except NotImplementedError:
    logging.warning('cpu_count() not implemented.')
    cpu_count = 4
  pool = ThreadPool(min(cpu_count, len(work_list)))
  def function_with_try(arg):
    try:
      function(arg)
    except Exception:  
      logging.exception('Exception while running %s' % function.__name__)
      if on_failure:
        on_failure(arg)
  try:
    pool.imap_unordered(function_with_try, work_list)
    pool.close()
    pool.join()
  finally:
    pool.terminate()
def ApplyInParallel ( function , work_list , on_failure = None ) : if not work_list : return try : cpu_count = multiprocessing . cpu_count ( ) // 2 if sys . platform == 'win32' : cpu_count = min ( cpu_count , 56 ) except NotImplementedError : logging . warning ( 'cpu_count() not implemented.' ) cpu_count = 4 pool = ThreadPool ( min ( cpu_count , len ( work_list ) ) ) def function_with_try ( arg ) : try : function ( arg ) except Exception : logging . exception ( 'Exception while running %s' % function . __name__ ) if on_failure : on_failure ( arg ) try : pool . imap_unordered ( function_with_try , work_list ) pool . close ( ) pool . join ( ) finally : pool . terminate ( )
Apply a function to all values in work_list in parallel.
Apply a function to all values in work_list in parallel .
"""Apply a function to all values in work_list in parallel.

  Args:
    function: A function with one argument.
    work_list: Any iterable with arguments for the function.
    on_failure: A function to run in case of a failure.
  """ # Note that this is speculatively halved as an attempt to fix # crbug.com/953365. # TODO(crbug.com/1190269) - we can't use more than 56 # cores on Windows or Python3 may hang. # Some platforms can raise a NotImplementedError from cpu_count() # pylint: disable=broad-except # logging exception here is the only way to get a stack trace since # multiprocessing's pool implementation does not save that data. See # crbug.com/953365.
function
A function with one argument.
A function with one argument .
work_list
Any iterable with arguments for the function.
Any iterable with arguments for the function .
on_failure
A function to run in case of a failure.
A function to run in case of a failure .