<commit_before>import json
import time
import logging

import requests

from threading import Thread
from datetime import datetime

logger = logging.getLogger(__name__)


def json_handler(obj):
    if isinstance(obj, datetime):
        return obj.isoformat()


class Publisher(object):
    def __init__(self, robot,
                 url='http://teahupoo.ddns.net/post/robot-state.json',
                 push_period=60):

        def pub_loop():
            while True:
                if not robot.alive:
                    continue

                try:
                    requests.post(
                        url=url,
                        data=json.dumps(robot.state,
                                        default=json_handler),
                        headers={
                            'content-type': 'application/json',
                        }
                    )
                except Exception as e:
                    msg = 'Could not post robot state: {}'.format(str(e))
                    logger.info(msg)

                time.sleep(push_period)

        self._pub = Thread(target=pub_loop)
        self._pub.daemon = True

    def start(self):
        self._pub.start()<commit_msg>Prevent an infinite loop when the robot crashes.<commit_after>import json
import time
import logging

import requests

from threading import Thread
from datetime import datetime

logger = logging.getLogger(__name__)


def json_handler(obj):
    if isinstance(obj, datetime):
        return obj.isoformat()


class Publisher(object):
    def __init__(self, robot,
                 url='http://teahupoo.ddns.net/post/robot-state.json',
                 push_period=60):

        def pub_loop():
            while True:
                time.sleep(push_period)

                if not robot.alive:
                    continue

                try:
                    requests.post(
                        url=url,
                        data=json.dumps(robot.state,
                                        default=json_handler),
                        headers={
                            'content-type': 'application/json',
                        }
                    )
                except Exception as e:
                    msg = 'Could not post robot state: {}'.format(str(e))
                    logger.info(msg)

        self._pub = Thread(target=pub_loop)
        self._pub.daemon = True

    def start(self):
        self._pub.start()
{'fraction_non_alphanumeric': 0.08404384896467722, 'fraction_numerical': 0.0016240357287860333, 'mean_word_length': 1.283595922150139, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2440104', 'n_tokens_mistral': 626, 'n_tokens_neox': 582, 'n_words': 142}