<commit_before># coding: utf-8

import base64
import commands
import json
import time

from functools import wraps
from flask import Response, current_app, request

from core.exceptions import CreationException, ConnectionError, \
    TimeoutException, SessionException
from core.config import config
from core.logger import log

from core import utils
from core.sessions import Session, RequestHelper
from vmpool import endpoint
from PIL import Image


def is_request_closed():
    return request.input_stream._wrapped.closed


def is_session_timeouted():
    if hasattr(request, 'session'):
        return request.session.timeouted
    return False


def is_session_closed():
    if hasattr(request, 'session'):
        return request.session.closed
    return False


def connection_watcher(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        for value in func(*args, **kwargs):
            if is_request_closed():
                raise ConnectionError("Client has disconnected")

            elif is_session_timeouted():
                raise TimeoutException("Session timeouted")

            elif is_session_closed():
                raise SessionException("Session closed")

            time.sleep(0)
        return value
    return wrapper


def save_screenshot(session, screenshot):
    if screenshot:
        log_step = session.current_log_step
        path = config.SCREENSHOTS_DIR + "/" + str(session.id) + \
            "/" + str(log_step.id) + ".png"
        utils.write_file(path, base64.b64decode(screenshot))
        log_step.screenshot = path
        log_step.save()<commit_msg>Connection_watcher sleep hotfix<commit_after># coding: utf-8

import base64
import commands
import json
import time

from functools import wraps
from flask import Response, request

from core.exceptions import CreationException, ConnectionError, \
    TimeoutException, SessionException
from core.config import config
from core.logger import log

from core import utils
from core.sessions import Session, RequestHelper
from vmpool import endpoint
from PIL import Image


def is_request_closed():
    return request.input_stream._wrapped.closed


def is_session_timeouted():
    if hasattr(request, 'session'):
        return request.session.timeouted
    return False


def is_session_closed():
    if hasattr(request, 'session'):
        return request.session.closed
    return False


def connection_watcher(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        for value in func(*args, **kwargs):
            if is_request_closed():
                raise ConnectionError("Client has disconnected")

            elif is_session_timeouted():
                raise TimeoutException("Session timeouted")

            elif is_session_closed():
                raise SessionException("Session closed")

            time.sleep(0.01)
        return value
    return wrapper


def save_screenshot(session, screenshot):
    if screenshot:
        log_step = session.current_log_step
        path = config.SCREENSHOTS_DIR + "/" + str(session.id) + \
            "/" + str(log_step.id) + ".png"
        utils.write_file(path, base64.b64decode(screenshot))
        log_step.screenshot = path
        log_step.save()
{'fraction_non_alphanumeric': 0.0811648079306072, 'fraction_numerical': 0.0055762081784386614, 'mean_word_length': 3.0413016270337923, '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': '4913299', 'n_tokens_mistral': 904, 'n_tokens_neox': 866, 'n_words': 248}