QProcess的子进程如何从父进程接收数据

时间:2019-04-16 05:39:33

标签: python pyqt pyqt5 communication qprocess

Hel?

我需要在不同的环境下操作两个不同的py文件。可以使用QProcess启动子进程。但我仍然不知道如何从父进程接收数据。

这是带有gui pytrader.py的父进程

def __init__(self):
    # super().__init__()
    QtWidgets.QMainWindow.__init__(self)
    form_class.__init__(self)
    self.setupUi(self)

    self.exeOperation = QProcess()
    self.Requirement_of_current_thread = Thread(target=self.Requirement_of_current)

 def Start_of_RLTrader(self):
             if not self.Requirement_of_current_thread.is_alive():
        if self.folderPath and self.transModelPath \
                and self.RLTraderPath3 and self.transStockCode:
            self.Requirement_of_current()
    return

 def Requirement_of_current(self):
      exeFilePath = os.path.abspath('C:/Users/netpilgrim/PycharmProjects/newTestAI/test.py')
    envPath = os.path.abspath('C:/python/envs/tensorflow_test_pyinstaller/python.exe')
    self.exeOperation.start(envPath, ['-u', exeFilePath])
    self.exeOperation.waitForStarted(-1)
    self.exeOperation.started.emit()
   self.exeOperation.setInputChannelMode(self.exeOperation.ManagedInputChannel)
    self.exeOperation.write(transData)
    self.exeOperation.waitForBytesWritten(1000)
    self.exeOperation.waitForReadyRead(100)
    self.exeOperation.closeWriteChannel()

这是带有gui test.py的子进程

class DataTransfer(QObject):
def __init__(self):
    super().__init__()
    self.GOP = 'this is Test'
    self.process = QProcess()
    self.process.start()
    self.process.waitForStarted(-1)
    self.process2 = self.process.readAll()
    # self.process.waitForReadyRead(1000)
    if self.process2:
        self.GOP = self.process2
    self.process3 = self.process.state()

class TestWindow(QWidget, DataTransfer):
def __init__(self):
    super().__init__()
    GP = DataTransfer()
    self.var002 = str(GP.GOP)
    self.var003 = str(GP.process2)
    self.var004 = str(GP.process3)
    self.initUI()

def initUI(self):
    self.setWindowTitle('My First Application')
    self.move(300, 300)
    self.resize(400, 200)

    label001 = QLabel(self)
    label001.setText(self.var002)
    val001 = label001.font()
    val001.setPointSize(30)
    label001.setFont(val001)
    label001.setAlignment(Qt.AlignCenter)

    label002 = QLabel(self)
    label002.setText(self.var003)
    label002.move(100,100)
    val002 = label002.font()
    val002.setPointSize(20)
    label002.setFont(val002)
    label002.setAlignment(Qt.AlignCenter)

    label003 = QLabel(self)
    label003.setText(self.var004)
    label003.move(100, 150)
    val003 = label003.font()
    val003.setPointSize(20)
    label003.setFont(val003)
    label003.setAlignment(Qt.AlignCenter)

    layout = QVBoxLayout()
    layout.addWidget(label001)
    layout.addWidget(label002)
    layout.addWidget(label003)

    self.show()

当我使用像子流程这样的input()函数时,没有出现GUI。那么如何将数据从pytrader.py传输到test.py?

0 个答案:

没有答案