<commit_before>import signal
from contextlib import contextmanager

class TimeoutException(Exception): pass

from argparse import ArgumentParser
parser = ArgumentParser(description='Starts script with a timeout.')
parser.add_argument('timeout', type=int, help='Timeout in seconds')
parser.add_argument('script', help='Script to be started.')
args = parser.parse_args()

@contextmanager
def time_limit(seconds):
    def signal_handler(signum, frame):
        raise TimeoutException, "Timed out!"
    signal.signal(signal.SIGALRM, signal_handler)
    signal.alarm(seconds)
    try:
        yield
    finally:
        signal.alarm(0)

try:
  import os
  with time_limit(args.timeout):
      os.system('python ' + args.script)
except TimeoutException, msg:
    print "Timed out!"<commit_msg>added return value for runWithTimelimit.py<commit_after>import signal
from contextlib import contextmanager

class TimeoutException(Exception): pass

from argparse import ArgumentParser
parser = ArgumentParser(description='Starts script with a timeout.')
parser.add_argument('timeout', type=int, help='Timeout in seconds')
parser.add_argument('script', help='Script to be started.')
args = parser.parse_args()

@contextmanager
def time_limit(seconds):
    def signal_handler(signum, frame):
        raise TimeoutException, "Timed out!"
    signal.signal(signal.SIGALRM, signal_handler)
    signal.alarm(seconds)
    try:
        yield
    finally:
        signal.alarm(0)

try:
  from subprocess import call
  with time_limit(args.timeout):
    return call('python ' + args.script, shell=True)
except TimeoutException, msg:
    print "Timed out!"
{'fraction_non_alphanumeric': 0.09920391916717697, 'fraction_numerical': 0.001224739742804654, 'mean_word_length': 4.773851590106007, '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': '2471182', 'n_tokens_mistral': 469, 'n_tokens_neox': 470, 'n_words': 129}