0
Hello I’m a beginner in Python and I’m creating a simple server but I can’t create independent threads. When the client connects to the server it calls the worker function that waits for a client message to send a response. It turns out that only one connection is executed at a time and in the order of connection, leaving the other customers who already sent the message waiting.
while True:
conn, address = ss.accept()
print('DEBUG: Connected by ', address)
obj = threading.Thread(target = ServerWorker.worker(conn))
obj.start()
Worker function:
def worker(conn):
print('Running...')
_in = conn.recv(1024)
msg = _in.decode(encoding = 'utf-8')
print('DEBUG: Processing ', msg, '...')
msg = 'ECHO: ' + msg
_out = conn.sendall(bytes(msg,encoding = 'utf-8'))
conn.close()
I just tried calling another script . py instead of the thread but I couldn’t pass the Conn object as argument. Please help me.
I got it. The thread really wasn’t created until the function ran. Thank you very much!
– Wanderson Lima
@Good that Wandersonlima helped! if my answer answered, consider marking it as accepted, to close the question.
– nosklo