Call the method without waiting for a response

I am trying to create a server side application to listen for connections and call a method based on what the client says. However, when I call the method load, I want to continue executing the code below the main one.

Is there anyway I can achieve this, or am I taking the wrong approach? The code is below;

def main(ipAddr, tcpPort, bufferSize, s):
    try:
        s.bind((ipAddr, tcpPort))
        s.listen(4)
        conn, addr = s.accept()

    print("Connection attempt from: %s" % addr)
    messageRecv = ""
    while True:
        data = conn.recv(bufferSize)
        if not data: break
        messageRecv = data.decode('utf-8')
finally:
    conn.close()
    if messageRecv == "Ready": upload(addr)

main(ipAddr, tcpPort, bufferSize, s)



def upload(addr):
    pass

      

+3


source to share


1 answer


Consider using a module multiprocessing

, which is essentially a Python "multithreading" package. The API is very similar to a module threading

, but threading

can be prohibitive due to the GIL .

In your case, you might have something like this:



p = Process(target=upload, args=(addr,))
p.start()
# some other code
p.join()

      

+1


source







All Articles