How many processes does a multi-process webserver support?

1

I have a server that must respond to multiple PCs at the time, but some respond to others not. Sometimes an alert comes up with the phrase: "Bad Gateway".

This led me to suppose that the server is not able to receive many requests, or is overloaded.

I add that I use the ThreadedHTTPServer method.

Here my code:

# -*- coding: utf-8 -*-
# Autor: Diego Lopez

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.common.exceptions import TimeoutException
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
import json
from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import signal
from SocketServer import ThreadingMixIn
import threading

class S(BaseHTTPRequestHandler):
    def _set_headers(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_GET(self):
       self._set_headers()
       self.wfile.write("<html><body><h1>hi!</h1></body></html>")

    def do_HEAD(self):
       self._set_headers()

   def do_POST(self):
       # Doesn't do anything with posted data
       content_length = int(self.headers['Content-Length']) # <--- Gets the 
       size of data
       post_data = self.rfile.read(content_length) # <--- Gets the data itself
       self._set_headers()
       try:
           data_string = json.loads(post_data)
       except:
           self.wfile.write('{"error" : "JSON"}')
           return

       placa = str(data_string["placa"])
       placa = placa.encode("utf8")
       print post_data

       scraping(placa,self)


class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
    """Handle requests in a separate thread."""      


def scraping(placa,self):
    #Aqui realizo una operacion de scraping que me limito en mostrar.
    self.wfile.write('{"estado" : "activo"}')
    return


if __name__ == "__main__":
    server = ThreadedHTTPServer(('', 8888), S)
    print 'Starting server, use <Ctrl-C> to stop'
    server.serve_forever()

But I do not know exactly what happens, that's why I ask you:

How many processes does a webserver written in python support? What am I doing wrong?

    
asked by Diego Lopez 20.01.2018 в 15:48
source

0 answers