How can I make a multithreading queue-system for incoming lines from a socket in Python?
Question: I'm fairly new to Python and I have a code that receives information from a
socket and processes each line one after one in a queue-system. The problem is
that if a line ever take an unusual amount of time to process, all the other
lines in the queue will have to wait.

How can I make it so that ones a new line is received, it will process it with
a thread, and make a new thread for every other line regardless if the first
thread has finished? I have looked at many other examples with multithreading
and queues but I just don't know how I can implement something like this into
my code. Any suggestions?

Here is how my queue-system currently looks like:

    
    
    while 1:
        readbuffer = readbuffer + s.recv(2048)
        temp = string.split(readbuffer, "\n")
        readbuffer = temp.pop()
    
        for line in temp:
            *code processing line*
    


Answer: For your requirement, the low-level threading API suffices. (For more
ambitious tasks, see the
[threading](https://docs.python.org/3.2/library/threading.html#module-
threading) module.)

    
    
    try:
        from _thread import start_new_thread
    except ImportError:
        from  thread import start_new_thread
    
    def process(line):
        #*code processing line*
    …
    for line in temp:
        start_new_thread(process, (line,))
    

