<commit_before>import fileinput
import re
import os
from subprocess import Popen
from config import Config
from time import sleep


def set_port(port, sim_dir):
    try:
        for line in fileinput.FileInput(sim_dir + 'unrealcv.ini', inplace=1):
            if "Port=" in line:
                line = re.sub('\d{4}', str(port), line)
            if "Width=" in line:
                line = re.sub('\d{2,4}', str(84), line)
            if "Height=" in line:
                line = re.sub('\d{2,4}', str(84), line)
            print line,
    except OSError or IOError:
        print('unrealcv.ini does not exist, launching Sim to create it')
        with open(os.devnull, 'w') as fp:
            sim = Popen(Config.SIM_DIR + Config.SIM_NAME, stdout=fp)
        sleep(5)
        sim.terminate()
        set_port(port, sim_dir)
<commit_msg>correcting error handling<commit_after>import fileinput
import re
import os
from subprocess import Popen
from config import Config
from time import sleep


def set_port(port, sim_dir):
    try:
        for line in fileinput.FileInput(sim_dir + 'unrealcv.ini', inplace=1):
            if "Port=" in line:
                line = re.sub('\d{4}', str(port), line)
            if "Width=" in line:
                line = re.sub('\d{2,4}', str(84), line)
            if "Height=" in line:
                line = re.sub('\d{2,4}', str(84), line)
            print line,
    except (OSError, IOError) as err:
        print(err)
        print('unrealcv.ini does not exist, launching Sim to create it')
        with open(os.devnull, 'w') as fp:
            sim = Popen(Config.SIM_DIR + Config.SIM_NAME, stdout=fp)
        sleep(5)
        sim.terminate()
        set_port(port, sim_dir)

{'fraction_non_alphanumeric': 0.12179487179487179, 'fraction_numerical': 0.01282051282051282, 'mean_word_length': 2.162062615101289, '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': '1490120', 'n_tokens_mistral': 560, 'n_tokens_neox': 550, 'n_words': 164}