def main(unused_argv):
  """Dump stats about all the actions that are in use in a set of replays."""
  run_config = run_configs.get()

  if not gfile.Exists(FLAGS.replays):
    sys.exit("{} doesn't exist.".format(FLAGS.replays))

  stats_queue = multiprocessing.Queue()
  stats_thread = threading.Thread(target=stats_printer, args=(stats_queue,))
  stats_thread.start()
  try:
    # For some reason buffering everything into a JoinableQueue makes the
    # program not exit, so save it into a list then slowly fill it into the
    # queue in a separate thread. Grab the list synchronously so we know there
    # is work in the queue before the SC2 processes actually run, otherwise
    # The replay_queue.join below succeeds without doing any work, and exits.
    print("Getting replay list:", FLAGS.replays)
    replay_list = sorted(run_config.replay_paths(FLAGS.replays))
    print(len(replay_list), "replays found.\n")
    replay_queue = multiprocessing.JoinableQueue(FLAGS.parallel * 10)
    replay_queue_thread = threading.Thread(target=replay_queue_filler,
                                           args=(replay_queue, replay_list))
    replay_queue_thread.daemon = True
    replay_queue_thread.start()

    for i in range(FLAGS.parallel):
      p = ReplayProcessor(i, run_config, replay_queue, stats_queue)
      p.daemon = True
      p.start()
      time.sleep(1)  # Stagger startups, otherwise they seem to conflict somehow

    replay_queue.join()  # Wait for the queue to empty.
  except KeyboardInterrupt:
    print("Caught KeyboardInterrupt, exiting.")
  finally:
    stats_queue.put(None)  # Tell the stats_thread to print and exit.
    stats_thread.join()
def main ( unused_argv ) : run_config = run_configs . get ( ) if not gfile . Exists ( FLAGS . replays ) : sys . exit ( "{} doesn't exist." . format ( FLAGS . replays ) ) stats_queue = multiprocessing . Queue ( ) stats_thread = threading . Thread ( target = stats_printer , args = ( stats_queue , ) ) stats_thread . start ( ) try : print ( "Getting replay list:" , FLAGS . replays ) replay_list = sorted ( run_config . replay_paths ( FLAGS . replays ) ) print ( len ( replay_list ) , "replays found.\n" ) replay_queue = multiprocessing . JoinableQueue ( FLAGS . parallel * 10 ) replay_queue_thread = threading . Thread ( target = replay_queue_filler , args = ( replay_queue , replay_list ) ) replay_queue_thread . daemon = True replay_queue_thread . start ( ) for i in range ( FLAGS . parallel ) : p = ReplayProcessor ( i , run_config , replay_queue , stats_queue ) p . daemon = True p . start ( ) time . sleep ( 1 ) replay_queue . join ( ) except KeyboardInterrupt : print ( "Caught KeyboardInterrupt, exiting." ) finally : stats_queue . put ( None ) stats_thread . join ( )
Dump stats about all the actions that are in use in a set of replays.