Hello, I'm a beginner in Python and I'm creating a simple server but I can not 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 connection order, leaving the other clients who have 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 tried just calling another .py script instead of the thread but could not pass the conn object as an argument. Please help me.