<commit_before># -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license. 
# See the NOTICE for more information.

import os

import gevent
from gevent import core
from gevent import monkey
monkey.noisy = False
from gevent.pool import Pool
from gevent import wsgi

import gunicorn
from gunicorn.workers.base import Worker

class WSGIHandler(wsgi.WSGIHandler):
    def log_request(self, *args):
        pass

class GEvent2Worker(Worker):
    
    base_env = {
        'GATEWAY_INTERFACE': 'CGI/1.1',
        'SERVER_SOFTWARE': 'gevent/%s gunicorn/%s' % (gevent.__version__,
                                                    gunicorn.__version__),
        'SCRIPT_NAME': '',
        'wsgi.version': (1, 0),
        'wsgi.url_scheme': 'http',
        'wsgi.multithread': False,
        'wsgi.multiprocess': True,
        'wsgi.run_once': False
    }
    
    def __init__(self, *args, **kwargs):
        super(GEvent2Worker, self).__init__(*args, **kwargs)
        self.worker_connections = self.cfg.worker_connections
        self.pool = None
    
    @classmethod
    def setup(cls):
        from gevent import monkey
        monkey.patch_all(dns=False)
   
    def handle_request(self, req):
        self.pool.spawn(self.handle, req)
       
    def handle(self, req):
        handle = WSGIHandler(req)
        handle.handle(self)
        
    def run(self):
        self.socket.setblocking(1)
        env = self.base_env.copy()
        
        env.update({
            'SERVER_NAME': self.address[0],
            'SERVER_PORT': str(self.address[1]) 
        })
        self.base_env = env
        
        http = core.http()
        http.set_gencb(self.handle_request)
        self.pool = Pool(self.worker_connections)
        
        self.application = self.wsgi
        acceptor = gevent.spawn(http.accept, self.socket.fileno())
        
        try:
            while self.alive:
                self.notify()
            
                if self.ppid != os.getppid():
                    self.log.info("Parent changed, shutting down: %s" % self)
                    gevent.kill(acceptor)
                    break
                gevent.sleep(0.1)            
            self.pool.join(timeout=self.timeout)
        except KeyboardInterrupt:
            pass


        
        
        <commit_msg>rewrite ggevent2 workerr to support last gevent 0.13. a lot more stable and faster than it was. gevent 0.13 give new streaming possibilities and keepalive.<commit_after># -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license. 
# See the NOTICE for more information.

import os

import gevent
from gevent import core
from gevent import monkey
monkey.noisy = False
from gevent.pool import Pool
from gevent import pywsgi

import gunicorn
from gunicorn.workers.base import Worker

class WSGIHandler(pywsgi.WSGIHandler):
    def log_request(self, *args):
        pass


class WSGIServer(pywsgi.WSGIServer):
    base_env = {'GATEWAY_INTERFACE': 'CGI/1.1',
                'SERVER_SOFTWARE': 'gevent/%s gunicorn/%s' % (gevent.__version__,
                                                            gunicorn.__version__),
                'SCRIPT_NAME': '',
                'wsgi.version': (1, 0),
                'wsgi.multithread': False,
                'wsgi.multiprocess': False,
                'wsgi.run_once': False}

        
    
class GEvent2Worker(Worker):

    
    def __init__(self, *args, **kwargs):
        super(GEvent2Worker, self).__init__(*args, **kwargs)
        self.worker_connections = self.cfg.worker_connections
    
    @classmethod
    def setup(cls):
        from gevent import monkey
        monkey.patch_all(dns=False)
        
    def run(self):
        self.socket.setblocking(1)
        pool = Pool(self.worker_connections)
        
        server = WSGIServer(self.socket, application=self.wsgi, 
                        spawn=pool, handler_class=WSGIHandler)
        
        acceptor = gevent.spawn(server.serve_forever)
        
        try:
            while self.alive:
                self.notify()
            
                if self.ppid != os.getppid():
                    self.log.info("Parent changed, shutting down: %s" % self)
                    gevent.kill(acceptor)
                    break
                gevent.sleep(0.1)            
            self.pool.join(timeout=self.timeout)
        except KeyboardInterrupt:
            pass


        
        
        
{'fraction_non_alphanumeric': 0.09663021646953805, 'fraction_numerical': 0.006471769694264673, 'mean_word_length': 1.7513812154696133, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7030819', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1290, 'n_words': 297}