<commit_before>import sys
import time
import signal
import client
import json
import logging
from six.moves import configparser

config = configparser.ConfigParser()
config.read("config.ini")
HOST = config.get("main", "host")
OAUTH_TOKEN = config.get("main", "oauth_token")
DEVICE_SPEC = config.get("main", "device_spec")

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s %(levelname)s %(message)s"
)


def exit_gracefully(signum, frame):
    stf.close_all()
    sys.exit(0)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, exit_gracefully)
    signal.signal(signal.SIGTERM, exit_gracefully)
    stf = client.SmartphoneTestingFarmClient(
        host=HOST,
        common_api_path="/api/v1",
        oauth_token=OAUTH_TOKEN,
    )
    with open(DEVICE_SPEC) as f:
        device_spec = json.load(f)
    stf.add_devices(device_spec=device_spec)
    try:
        stf.connect_to_mine()
    except:
        exit_gracefully()
    while True:
        time.sleep(100)<commit_msg>fix exception handling<commit_after>import sys
import time
import signal
import client
import json
import logging
from six.moves import configparser

config = configparser.ConfigParser()
config.read("config.ini")
HOST = config.get("main", "host")
OAUTH_TOKEN = config.get("main", "oauth_token")
DEVICE_SPEC = config.get("main", "device_spec")

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s %(levelname)s %(message)s"
)


def exit_gracefully(signum, frame):
    stf.close_all()
    sys.exit(0)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, exit_gracefully)
    signal.signal(signal.SIGTERM, exit_gracefully)
    stf = client.SmartphoneTestingFarmClient(
        host=HOST,
        common_api_path="/api/v1",
        oauth_token=OAUTH_TOKEN,
    )
    with open(DEVICE_SPEC) as f:
        device_spec = json.load(f)
    stf.add_devices(device_spec=device_spec)
    try:
        stf.connect_to_mine()
    except Exception as e:
        stf.close_all()
        raise e
    while True:
        time.sleep(100)
{'fraction_non_alphanumeric': 0.11756097560975609, 'fraction_numerical': 0.004878048780487805, 'mean_word_length': 3.7367205542725173, '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': '6404590', 'n_tokens_mistral': 717, 'n_tokens_neox': 703, 'n_words': 134}