I'm 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 upload i want to continue executing code under main.
Is there anyway i can achieve this, or am i taking the incorrect approach? Code 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
Consider using the multiprocessing module, which is essentially Python's "multithreading" package. The API is very similar to the threading module's, but threading may be prohibitive due to the GIL.
In your case, you may have something like this:
p = Process(target=upload, args=(addr,))
p.start()
# some other code
p.join()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With