<commit_before>#!/usr/bin/env python3
import os
import sys
import time
import signal
import traceback
from panda import Panda
from multiprocessing import Pool

jungle = "JUNGLE" in os.environ
if jungle:
  from panda_jungle import PandaJungle # pylint: disable=import-error

import cereal.messaging as messaging
from selfdrive.boardd.boardd import can_capnp_to_can_list

def initializer():
  """Ignore CTRL+C in the worker process.
  source: https://stackoverflow.com/a/44869451 """
  signal.signal(signal.SIGINT, signal.SIG_IGN)

def send_thread(sender_serial):
  global jungle
  try:
    if jungle:
      sender = PandaJungle(sender_serial)
    else:
      sender = Panda(sender_serial)
      sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
    sender.set_can_loopback(False)

    can_sock = messaging.sub_sock('can')

    while True:
      # Send messages one bus 0 and 1
      tsc = messaging.recv_one(can_sock)
      snd = can_capnp_to_can_list(tsc.can)
      snd = list(filter(lambda x: x[-1] <= 2, snd))
      sender.can_send_many(snd)

      # Drain panda message buffer
      sender.can_recv()
  except Exception:
    traceback.print_exc()

if __name__ == "__main__":
  if jungle:
    serials = PandaJungle.list()
  else:
    serials = Panda.list()
  num_senders = len(serials)

  if num_senders == 0:
    print("No senders found. Exiting")
    sys.exit(1)
  else:
    print("%d senders found. Starting broadcast" % num_senders)

  pool = Pool(num_senders, initializer=initializer)
  pool.map_async(send_thread, serials)

  while True:
    try:<commit_msg>handle nak error in replay many<commit_after>#!/usr/bin/env python3
import os
import sys
import time
import signal
import traceback
import usb1
from panda import Panda
from multiprocessing import Pool

jungle = "JUNGLE" in os.environ
if jungle:
  from panda_jungle import PandaJungle # pylint: disable=import-error

import cereal.messaging as messaging
from selfdrive.boardd.boardd import can_capnp_to_can_list

def initializer():
  """Ignore CTRL+C in the worker process.
  source: https://stackoverflow.com/a/44869451 """
  signal.signal(signal.SIGINT, signal.SIG_IGN)

def send_thread(sender_serial):
  global jungle
  try:
    if jungle:
      sender = PandaJungle(sender_serial)
    else:
      sender = Panda(sender_serial)
      sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
    sender.set_can_loopback(False)

    can_sock = messaging.sub_sock('can')

    while True:
      # Send messages one bus 0 and 1
      tsc = messaging.recv_one(can_sock)
      snd = can_capnp_to_can_list(tsc.can)
      snd = list(filter(lambda x: x[-1] <= 2, snd))

      try:
        sender.can_send_many(snd)
      except usb1.USBErrorTimeout:
        print("Can TX overflow", sender_serial)

      # Drain panda message buffer
      sender.can_recv()
  except Exception:
    traceback.print_exc()

if __name__ == "__main__":
  if jungle:
    serials = PandaJungle.list()
  else:
    serials = Panda.list()
  num_senders = len(serials)

  if num_senders == 0:
    print("No senders found. Exiting")
    sys.exit(1)
  else:
    print("%d senders found. Starting broadcast" % num_senders)

  pool = Pool(num_senders, initializer=initializer)
  pool.map_async(send_thread, serials)

  while True:
    try:
{'fraction_non_alphanumeric': 0.0946818321549339, 'fraction_numerical': 0.009837073470642483, 'mean_word_length': 3.641940085592011, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7375500', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1100, 'n_words': 275}