예제 #1
0
파일: wsgi.py 프로젝트: bigmlcom/pylibs
 def __init__(self, socket_or_address, application, **kwargs):
     handler_class = kwargs.pop('handler_class', None)
     if handler_class is not None:
         self.handler_class = handler_class
     HTTPServer.__init__(self, **kwargs)
     self.address = socket_or_address
     self.application = application
예제 #2
0
파일: wsgi.py 프로젝트: strogo/pylibs
 def __init__(self, socket_or_address, application, **kwargs):
     handler_class = kwargs.pop('handler_class', None)
     if handler_class is not None:
         self.handler_class = handler_class
     HTTPServer.__init__(self, **kwargs)
     self.address = socket_or_address
     self.application = application
예제 #3
0
def run():
    addr = (natip, int(sys.argv[1]) if len(sys.argv) > 1 else 10020)
    backlog = 64
    app = WsgiApp()
    if gevent.version_info < (0, 13, 7):
        HTTPServer(app).serve_forever(socket_or_address=addr, backlog=backlog)
    else:
        HTTPServer(listener=addr, handle=app, backlog=backlog).serve_forever()
예제 #4
0
파일: wsgi.py 프로젝트: vijvijay/rapidapp
 def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None):
     HTTPServer.__init__(self, listener, backlog=backlog, spawn=spawn)
     if application is not None:
         self.application = application
     if handler_class is not None:
         self.handler_class = handler_class
     if log == 'default':
         self.log = sys.stderr
     else:
         self.log = log
     self.set_environ(environ)
예제 #5
0
 def __init__(self,
              listener,
              application=None,
              backlog=None,
              spawn='default',
              log='default',
              handler_class=None,
              environ=None):
     HTTPServer.__init__(self, listener, backlog=backlog, spawn=spawn)
     if application is not None:
         self.application = application
     if handler_class is not None:
         self.handler_class = handler_class
     if log == 'default':
         self.log = sys.stderr
     else:
         self.log = log
     self.set_environ(environ)
예제 #6
0
파일: wsgi.py 프로젝트: strogo/pylibs
 def start(self):
     if self.listeners:
         raise AssertionError('WSGIServer.start() cannot be called more than once')
     sock = HTTPServer.start(self, self.address, backlog=self.backlog)
     self.address = sock.getsockname()
     env = self.base_env.copy()
     env.update( {'SERVER_NAME': socket.getfqdn(self.server_host),
                  'SERVER_PORT': str(self.server_port) } )
     self.base_env = env
     return sock
예제 #7
0
파일: wsgi.py 프로젝트: bigmlcom/pylibs
 def start(self):
     if self.listeners:
         raise AssertionError(
             'WSGIServer.start() cannot be called more than once')
     sock = HTTPServer.start(self, self.address, backlog=self.backlog)
     self.address = sock.getsockname()
     env = self.base_env.copy()
     env.update({
         'SERVER_NAME': socket.getfqdn(self.server_host),
         'SERVER_PORT': str(self.server_port)
     })
     self.base_env = env
     return sock
예제 #8
0
                  ', 100ms<t<1s: ' + str(mysql_stat["ttl100ms1s"]) + \
                  ', 1s<t<10s: ' + str(mysql_stat["ttl1s10s"]) + \
                  ', 10s<t: ' + str(mysql_stat["ttlmore10s"]) + "\n"
            i += 1
        request.add_output_header('Connection', 'close')
        request.add_output_header('Content-type', 'text/plain')
        request.add_output_header('Content-length', str(len(msg)))
        request.send_reply(200, 'OK', msg)
    pass

def process_stats():
    print "This is a stats processing thread"
    while True:
        time.sleep(60)
        print "Let's process stats"

setproctitle("yybal")
mysql_stats = []
# The connection state should not be defined globally, it should be isolated at a connection level
# to prevent situations when a server becomes alive for not properly initialized conns
# We use this global state for reporting only
#       Question: what to do with persistent connections?
mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0})
mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0})
thread.start_new_thread(process_stats, ())
gevent.monkey.patch_socket()
statsserver = HTTPServer(('', 9080), stathandler)
statsserver.start()
server = StreamServer(('127.0.0.1', 33306), handle) # creates a new server
server.serve_forever() # start accepting new connections
예제 #9
0
 def pre_start(self):
     HTTPServer.pre_start(self)
     if 'SERVER_NAME' not in self.environ:
         self.environ['SERVER_NAME'] = socket.getfqdn(self.server_host)
     self.environ.setdefault('SERVER_PORT', str(self.server_port))
예제 #10
0
파일: wsgi.py 프로젝트: vijvijay/rapidapp
 def pre_start(self):
     HTTPServer.pre_start(self)
     if 'SERVER_NAME' not in self.environ:
         self.environ['SERVER_NAME'] = socket.getfqdn(self.server_host)
     self.environ.setdefault('SERVER_PORT', str(self.server_port))
예제 #11
0
stuff = []


def handle(request):
    global global_counter, stuff
    if request.uri == '/guess':
        text = request.input_buffer.read()
        stuff.append(text)
        if len(stuff) > 100:
            stuff.pop(0)
            global_counter += 1
        request.send_reply(200, "OK", "")
        e.set()
    elif request.uri.startswith('/wait/'):
        counter = int(request.uri[6:])
        print counter, global_counter, stuff
        if counter >= (global_counter + len(stuff)):
            e.clear()
            e.wait()
        i = counter - global_counter
        if i < 0:
            i = 0
        counter = global_counter + len(stuff)
        request.send_reply(
            200, "OK", '{"counter":' + str(counter) + ', "guesses":[' +
            ','.join(stuff[i:]) + ']}')


server = HTTPServer(('127.0.0.1', 8001), handle)
server.serve_forever()
예제 #12
0
e = Event()
global_counter = 0
stuff = []

def handle(request):
    global global_counter, stuff
    if request.uri == '/guess':
        text = request.input_buffer.read()
        stuff.append(text)
        if len(stuff) > 100:
            stuff.pop(0)
            global_counter += 1
        request.send_reply(200,"OK","")
        e.set()
    elif request.uri.startswith('/wait/'):
        counter = int(request.uri[6:])
        print counter, global_counter, stuff
        if counter >= (global_counter + len(stuff)):
            e.clear()
            e.wait()
        i = counter - global_counter
        if i < 0:
            i = 0
        counter = global_counter + len(stuff)
        request.send_reply(200,"OK",
                '{"counter":'+str(counter)+', "guesses":['+','.join(stuff[i:])+']}')

server = HTTPServer(('127.0.0.1', 8001), handle)
server.serve_forever()