python :- can't start new thread
Question: i need to know why when i run the below code it gives me this error

    
    
    Traceback (most recent call last):
      File "C:\Users\moksh\Desktop\moksh.py", line 29, in <module>
        server_B_thread.start()
    error: can't start new thread
    

Code:

    
    
    #!/usr/bin/python
    
    import threading
    import time
    import SocketServer
    import socket 
    
    class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
    
        def handle(self):
            self.allow_reuse_address = True
            self.data = self.request.recv(1024).strip()
            print "%s wrote: " % self.client_address[0]
            print 'Connection from',self.client_address[0]
            print self.data
            self.request.send(self.data.upper())
    
    class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
        pass
    
    if __name__ == "__main__":
    
        HOST = '0.0.0.0'
        PORT = 1000
        while PORT <1900: 
           server_B = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
           server_B_thread = threading.Thread(target=server_B.serve_forever)
           server_B_thread.setDaemon(True)
           server_B_thread.start()
           PORT +=1
    
        while 1:
            time.sleep(1)
    


Answer: You're trying to start 900 threads, and probably hitting a limit on the OS. I
don't know what you're trying to do, but I would look into
[Twisted](https://twistedmatrix.com/trac/), which will probably have more
options for running a high volume TCP server.

