Exemplo n.º 1
0
    def __init__(self,
                 listener,
                 application=None,
                 backlog=2048,
                 socket_type=socket.SOCK_STREAM,
                 address_family=socket.AF_INET,
                 disable_monkeypatch=False,
                 **kw):
        self.address_family = address_family
        self.socket_type = socket_type
        if not disable_monkeypatch:
            from meinheld import patch
            patch.patch_all()
        server.set_backlog(backlog)
        host, port = listener
        if host.startswith('fd://'):
            fd = int(host.split('://')[1])
            server.set_listen_socket(fd)
        else:
            if self.address_family == socket.AF_UNIX:
                filename = listener[0][len('unix:'):]

                try:
                    os.remove(filename)
                except OSError:
                    pass
                server.listen(filename)
            else:
                server.listen(listener)

        self.application = application
Exemplo n.º 2
0
    def __init__(
        self, listener, application=None, backlog=2048, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET
    ):
        self.address_family = address_family
        self.socket_type = socket_type
        from meinheld import patch

        patch.patch_all()
        server.set_backlog(backlog)
        host, port = listener
        if host.startswith("fd://"):
            fd = int(host.split("://")[1])
            server.set_listen_socket(fd)
        else:
            if self.address_family == socket.AF_UNIX:
                filename = listener[0][len("unix:") :]

                try:
                    os.remove(filename)
                except OSError:
                    pass
                server.listen(filename)
            else:
                server.listen(listener)

        self.application = application
Exemplo n.º 3
0
 def run(self, port, hostname, **kwargs):
     from meinheld import server, patch
     patch.patch_all()
     print(" - Running Hosting Server using Meinheld")
     print(" - http://%s:%s/" % (hostname, port))
     server.listen((hostname, port))
     server.run(self.app)
Exemplo n.º 4
0
 def __call__(self, environ, start_response):
     from meinheld import patch
     patch.patch_all()
     status = '200 OK'
     response_headers = [('Content-type','text/plain')]
     start_response(status, response_headers)
     self.environ = environ.copy()
     print(environ)
     return RESPONSE
Exemplo n.º 5
0
    def __init__(self, listener, application=None, backlog=2048):
        from meinheld import patch
        patch.patch_all()
        server.set_backlog(backlog)
        host, port = listener
        if host.startswith('fd://'):
            fd = int(host.split('://')[1])
            server.set_listen_socket(fd)
        else:
            server.listen(listener)

        self.application = application
    def run(self, port, hostname, **kwargs):
        if port is None:
            port = self.app.config.setdefault('LISTEN_PORT', 8000)
        if hostname is None:
            hostname = self.app.config.setdefault('LISTEN_HOST', '127.0.0.1')

        from meinheld import server, patch
        patch.patch_all()
        print(" - Running Hosting Server using Meinheld")
        print(" - http://%s:%s/" % (hostname, port))
        server.listen((hostname, port))
        server.run(self.app)
Exemplo n.º 7
0
def setup_bench(config):
    # early patch
    if config.backend in ('gevent', 'fastgevent'):
        from gevent import monkey
        monkey.patch_all()
    elif config.backend == 'meinheld':
        from meinheld import patch
        patch.patch_all()

    # starting 10 threads in the background
    for i in range(10):
        th = _FakeDBThread()
        th.start()
        _DBS.put(th)

    time.sleep(0.2)
Exemplo n.º 8
0
def setup_bench(config):
    # early patch
    if config.backend in ('gevent', 'fastgevent'):
        from gevent import monkey
        monkey.patch_all()
    elif config.backend == 'meinheld':
        from meinheld import patch
        patch.patch_all()

    # starting 10 threads in the background
    for i in range(10):
        th = _FakeDBThread()
        th.start()
        _DBS.put(th)

    time.sleep(0.2)
Exemplo n.º 9
0
from meinheld import server, middleware, patch
patch.patch_all()

from pymongo import Connection


def insert():

    from pymongo import Connection
    connection = Connection()

    db = connection.test_database
    test_collection = db.test_collection

    for i in xrange(10):
        name = "long name %s" % i
        data = "A" * 1024 * 1024
        if test_collection.insert(dict(id=i, index=i, name=name, data=data)):
            pass

    for t in test_collection.find():
        pass


def wsgi_app(environ, start_response):
    status = '200 OK'
    res = "Hello world!"
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    insert()
    return [res]
Exemplo n.º 10
0
from meinheld import server
import requests  # requests should not be pached
from meinheld import patch
patch.patch_all()
import time


running = False

def start_server(app, middleware=None):
    global running 
    if running:
        return

    server.listen(("0.0.0.0", 8000))
    running = True
    if middleware:
        server.run(middleware(app))
    else:
        server.run(app)

    return app.environ


class ServerRunner(object):


    def __init__(self, app, middleware=None):
        self.app = app
        self.middleware = middleware
        self.running = False
Exemplo n.º 11
0
#!/usr/bin/python
from meinheld import patch; patch.patch_all()
from meinheld import server, middleware
import sys
import os
import traceback
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import call_command
from django.core.signals import got_request_exception

sys.path.append('..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_chat.settings'

def exception_printer(sender, **kwargs):
    traceback.print_exc()

got_request_exception.connect(exception_printer)

call_command('syncdb')
print 'Serving on 8088...'
server.listen(('0.0.0.0', 8088))
server.run(middleware.ContinuationMiddleware(WSGIHandler()))