I am trying out basic server program which listens on port and for each incoming request, it spawns new daemon thread and continues execution. Earlier similar code used to work, now this thing is not working.
server.py
import multiprocessing as mu
from time import sleep
from random import random
import socket
def worker():
while(True):
print("Inside worker....")
sleep(2)
socketObj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("127.0.0.1", 8080)
socketObj.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
socketObj.bind(server_address)
socketObj.listen(10)
while(True):
print("Listening...")
data_socket, client_address = socketObj.accept()
a = data_socket.recv(9000)
p = mu.Process(target=worker, args=())
p.daemon = True
p.start()
client.py
import socket
s = "dummydata"
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect(('127.0.0.1', 8080))
socket.send(str.encode(s))
I first ran server and then client. Somehow, it kept printing Listening...
for each request (in fact it sometimes printed it twice) and never printed Inside worker...
. Why the daemon thread is never spawned? Is it behaving same on your machine? If yes why?