Cách tốt nhất để thiết lập giao tiếp giữa hai quy trình trong python là gì? Sau khi một số googling, tôi đã cố gắng để làm như vậy:Quy trình giao tiếp bằng Python
parent_pipe, child_pipe = Pipe()
p = Process(target = instance_tuple.instance.run(), \
args = (parent_pipe, child_pipe,))
p.start()
gửi dữ liệu đến quá trình con:
command = Command(command_name, args)
parent_pipe.send(command)
Process mục tiêu chức năng:
while True:
if (self.parent_pipe.poll()):
command = parent_pipe.recv()
if (command.name == 'init_model'):
self.init_model()
elif (command.name == 'get_tree'):
tree = self.get_fidesys_tree(*command.args)
result = CommandResult(command.name, tree)
self.child_pipe.send(result)
elif(command.name == 'set_variable'):
name = command.args[0]
value = command.args[1]
self.config[name] = value
Nhưng nó dường như không làm việc (quá trình con không nhận được bất cứ điều gì thông qua parent_pipe
). Làm thế nào tôi có thể sửa chữa nó?
Xin cảm ơn trước.
Kiểm tra parent_pipe. Nó có bao giờ được khởi tạo không? – krs1
@ krs1 Có, cả ở trẻ em và cha mẹ xử lý đường ống được khởi tạo. –