<commit_before>#-*-coding:utf-8-*-

import errno
import select
import socket
from http_parser.http import NoMoreData
from larus import wsgi
from larus.workers.base import BaseWorker


class SyncWorker(BaseWorker):

    def run(self):
        [sock.setblocking(0) for sock in self.sockets]
        while True:
            readables, _, _ = select.select(self.sockets, [], [], self.timeout)
            for sock in readables:
                client = None
                try:
                    client, addr = sock.accept()
                except socket.error as e:
                    if client and hasattr(client, 'close'):
                        client.close()
                    if e.args[0] not in (errno.EAGAIN,):
                        raise
                else:
                    self.handle(sock, client, addr)

    def handle(self, server, client, addr):
        try:
            environ, response = wsgi.create(server, client, self.config)
        except NoMoreData:
            client.close()

        result = self.app(environ, response.start_response)
        try:
            for data in result:
                response.send_data(data)
            response.close()
        except Exception as e:
            raise e
        finally:
            client.close()
            if hasattr(result, 'close'):
                result.close()<commit_msg>handle app exception<commit_after>#-*-coding:utf-8-*-

import errno
import select
import socket
from http_parser.http import NoMoreData
from larus import wsgi
from larus.workers.base import BaseWorker


class SyncWorker(BaseWorker):

    def run(self):
        [sock.setblocking(0) for sock in self.sockets]
        while True:
            readables, _, _ = select.select(self.sockets, [], [], self.timeout)
            for sock in readables:
                client = None
                try:
                    client, addr = sock.accept()
                except socket.error as e:
                    if client and hasattr(client, 'close'):
                        client.close()
                    if e.args[0] not in (errno.EAGAIN,):
                        raise
                else:
                    self.handle(sock, client, addr)

    def handle(self, server, client, addr):
        try:
            environ, response = wsgi.create(server, client, self.config)
        except NoMoreData:
            client.close()

        result = None
        try:
            result = self.app(environ, response.start_response)
            for data in result:
                response.send_data(data)
        except Exception as e:
            raise e
        finally:
            response.close()
            client.close()
            if hasattr(result, 'close'):
                result.close()
{'fraction_non_alphanumeric': 0.08939558450959102, 'fraction_numerical': 0.002171552660152009, 'mean_word_length': 1.4945848375451263, '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': '7019186', 'n_tokens_mistral': 740, 'n_tokens_neox': 699, 'n_words': 201}