I need some help with multiprocessing module of python. I am using Python3.6.6. My code structure is somewhat like this:
class ABC():
def __init__(self):
self.HOST = 'hostserver.com'
self.TCP_PORT = 0123
self.BUFFER_SIZE = 1024
self.SERVER_INFO = ""
self.SOCK = None
def connect_socket(self):
self.SOCK = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.SOCK.settimeout(1)
self.SOCK.connect((self.HOST, self.TCP_PORT))
self.SOCK.setblocking(True)
def recTask(self):
while True:
self.receive_data()
time.sleep(0.01)
def sendTask(self):
while True:
self.SOCK.sendall(bytes)
print("\n*Message sent*\n")
time.sleep(0.01)
if __name__ == '__main__':
Class_obj = ABC()
id = Class_obj.connect_socket()
ts = mp.Process(name='send_Process', target=Class_obj.sendTask())
ts.daemon = True
tr = mp.Process(name='rec_Process', target=Class_obj.recTask())
tr.daemon = True
tr.start()
ts.start()
ts.join()
tr.join()
Can I call the methods of the same class using objects within the process? I want the 2 functions to run independently of each other. Also, when I run this I just see the "Message sent" being printed. In receive_data() function I have print("Message received") but it never prints. When I comment the code
ts = mp.Process(name='send_Process', target=Class_obj.sendTask())
ts.daemon = True
ts.start()
I see the "Message Received" being printed. Is there something which I am missing?