<commit_before>import struct
import select
import thread
from pysimplelog import Logger


class Barcode:

    def __init__(self, device, callback):
        self.file = open(device, 'rb')
        self.callback = callback
        self.logger = Logger('Barcode scan')
        thread.start_new_thread(self.listen, ())

    def listen(self):
        while True:
            self.callback(self.scan())

    def scan(self):
        self.logger.info('Waiting for scanner data')

        # Wait for binary data from the scanner and then read it
        scan_complete = False
        scanner_data = ''
        while True:
            rlist, _wlist, _elist = select.select([self.file], [], [], 0.1)
            if rlist != []:
                new_data = ''
                while not new_data.endswith('\x01\x00\x1c\x00\x01\x00\x00\x00'):
                    new_data = rlist[0].read(16)
                    scanner_data += new_data
                # There are 4 more keystrokes sent after the one we matched against,<commit_msg>catch all exceptions and keep scanning<commit_after>import struct
import select
import thread
from pysimplelog import Logger


class Barcode:

    def __init__(self, device, callback):
        self.file = open(device, 'rb')
        self.callback = callback
        self.logger = Logger('Barcode scan')
        thread.start_new_thread(self.listen, ())

    def listen(self):
        while True:
            try:
                self.callback(self.scan())
            except Exception, e:
                self.logger.error(e)

    def scan(self):
        self.logger.info('Waiting for scanner data')

        # Wait for binary data from the scanner and then read it
        scan_complete = False
        scanner_data = ''
        while True:
            rlist, _wlist, _elist = select.select([self.file], [], [], 0.1)
            if rlist != []:
                new_data = ''
                while not new_data.endswith('\x01\x00\x1c\x00\x01\x00\x00\x00'):
                    new_data = rlist[0].read(16)
                    scanner_data += new_data
                # There are 4 more keystrokes sent after the one we matched against,
{'fraction_non_alphanumeric': 0.10093023255813953, 'fraction_numerical': 0.01953488372093023, 'mean_word_length': 1.9185888738127543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3904725', 'n_tokens_mistral': 656, 'n_tokens_neox': 606, 'n_words': 167}