<commit_before>import json
import threading

from judge.models import LanguageLimit
from judge.rabbitmq import connection


_local = threading.local()


def channel():
    if hasattr(_local, 'chan'):
        return _local.chan
    chan = _local.chan = connection.connect().channel()
    return chan


def judge_submission(submission):
    problem = submission.problem
    time, memory = problem.time_limit, problem.memory_limit
    try:
        limit = LanguageLimit.objects.get(problem=problem, language=submission.language_id)
    except LanguageLimit.DoesNotExist:
        pass
    else:
        time, memory = limit.time_limit, limit.memory_limit

    chan = channel()
    result = chan.queue_declare(queue='sub-%d' % submission.id)
    if not result.method.consumer_count:
        chan.basic_publish(exchange='', routing_key='submission-id', body=str(submission.id))
    chan.basic_publish(exchange='', routing_key='submission', body=json.dumps({
        'id': submission.id,
        'problem': problem.code,
        'language': submission.language.key,
        'source': submission.source,
        'time-limit': time,
        'memory-limit': memory,
        'short-circuit': problem.short_circuit,
    }).encode('zlib'))


def abort_submission(submission):
    channel().basic_publish(exchange='broadcast', body=json.dumps({
        'action': 'abort-submission',
        'id': submission.id,
    }).decode('zlib'))
<commit_msg>Implemented abortion<commit_after>import json
import threading

from judge.models import LanguageLimit
from judge.rabbitmq import connection


_local = threading.local()


def channel():
    if hasattr(_local, 'chan'):
        return _local.chan
    chan = _local.chan = connection.connect().channel()
    return chan


def judge_submission(submission):
    problem = submission.problem
    time, memory = problem.time_limit, problem.memory_limit
    try:
        limit = LanguageLimit.objects.get(problem=problem, language=submission.language_id)
    except LanguageLimit.DoesNotExist:
        pass
    else:
        time, memory = limit.time_limit, limit.memory_limit

    chan = channel()
    result = chan.queue_declare(queue='sub-%d' % submission.id)
    if not result.method.consumer_count:
        chan.basic_publish(exchange='', routing_key='submission-id', body=str(submission.id))
    chan.basic_publish(exchange='', routing_key='submission', body=json.dumps({
        'id': submission.id,
        'problem': problem.code,
        'language': submission.language.key,
        'source': submission.source,
        'time-limit': time,
        'memory-limit': memory,
        'short-circuit': problem.short_circuit,
    }).encode('zlib'))


def abort_submission(submission):
    channel().basic_publish(exchange='broadcast', routing_key='', body=json.dumps({
        'action': 'abort-submission',
        'id': submission.id,
    }).encode('zlib'))

{'fraction_non_alphanumeric': 0.12807199723087573, 'fraction_numerical': 0.0, 'mean_word_length': 3.536891679748823, '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': '7360451', 'n_tokens_mistral': 881, 'n_tokens_neox': 835, 'n_words': 170}