Multiprocessing with Python and Arguements
Question: related to my last post (Which somehow got marked off and closed), I wrote
some code to create a thread for a command handler for my python TCP listener.
What basically happens is that I send in some data and it goes in the TCP
connecter. Then the TCP connector creates another process and sends the data
that it received through the process to the function in the command listener.
I do not know what is going on. Please help!

    
    
                import socket
        import sys
        import errno
        from multiprocessing import Process, Queue  # @UnresolvedImport
        import CommandHandler
    
    
        class tcpconnection:
            def tcp(self):
                data = ''
                q = Queue()
                p = Process(target=CommandHandler.CommandHandler.commands(), args=(self, data))
                #
                HOST = ''                 # Symbolic name meaning all available interfaces
                PORT = 9999              # Arbitrary non-privileged port
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.bind((HOST, PORT))
                s.listen(1)
                conn, addr = s.accept()
                print('Connected by', addr)
                while True:
                    data = conn.recv(1024)
                    p.start()
                    p.join()
                    if not data: break
                    conn.send(data)
                conn.close()
    

Says that:

    
    
        p = Process(target=CommandHandler.CommandHandler.commands(), args=(self, data))
        TypeError: unbound method commands() must be called with CommandHandler instance as first argument (got nothing instead)
    


Answer: `target=CommandHandler.CommandHandler.commands()` sets the `target` argument
to the result of the invocation of the `commands` method. What you probably
intended to do was to use that method as tharget, so you should use:

    
    
    p = Process(target=CommandHandler.CommandHandler.commands, args=(self, data))
    

Also the error tells you that you're trying to call an unbound method on a
class, but you need an object to call it on, probably:

    
    
    p = Process(target=CommandHandler.CommandHandler().commands, args=(self, data))
    

but that's not your only issue:

    
    
    while True:
        data = conn.recv(1024)
        p.start()
        p.join()
    

This loop will fail after the first invocation, because you can't restart an
already started process.

