practice_code/python/test/test2.py
2024-04-17 16:45:36 +08:00

33 lines
1.0 KiB
Python

import json
import threading
from multiprocessing.connection import Client
class ProcessClient:
def __init__(self):
self.Process_port = 3244
self.Process_server = 'localhost'
self.Process_client_Client = Client((self.Process_server, self.Process_port))
Process_client_recv = threading.Thread(target=self.Process_client_recv)
Process_client_recv.start()
def Process_client_send(self, target, function, content):
data = {"target": target, "function": function, "content": content}
data_json = json.dumps(data)
self.Process_client_Client.send(data_json)
def Process_client_recv(self):
while True:
try:
data_json = self.Process_client_Client.recv()
data = json.loads(data_json)
self.Process_client_pick(data)
except EOFError:
print("连接已关闭")
break
def Process_client_pick(self, data):
pass
if __name__ == '__main__':
ProcessClient()