M
M
MonkIncr2014-01-31 10:58:40
Python
MonkIncr, 2014-01-31 10:58:40

How to get stdout in realtime and not at the end of command processing (python3 pyqt/pyside subprocess)?

I am writing a program that runs rsync.
The program has two classes: Rsync, MyGUI
The launch itself is done like this

self.command = [
            "/usr/bin/rsync",
другие параметры,
            ]

cmd = list(self.command)

p = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

The answer is output through at the end of the iteration there is a text area trying to send text there through But the text appears in its entirety and only when the process is completely completed, while if the next instruction displays the text via print (), then everything is fine, it is output line by line to the console. Tell me how to fix it, if necessary, I will provide the source.
for line in p.stdout:
p.stdout.flush()
self.runningEdit = QtGui.QTextEdit()
self.runningEdit.append(x)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MonkIncr, 2014-01-31
@MonkIncr

def main():
    
    app = QtGui.QApplication(sys.argv)
    ex = MyGUI()
    
    login = "login"
    server = "x.x.x.x"
    src = "/home/***/rsync/"
    dst = "/srv/***/remote"
    rs = Rsync(ex, login, server, src, dst)
    ex.button_connect(rs)

    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Thanks, I'll take a look.

M
MonkIncr, 2014-02-04
@MonkIncr

It is quite possible that this is wrong , but since print(x) itself is in a function, in the MyGUI class , and the call comes from a loop in the Rsync class , and the output to the console occurs, and in QtGui.QTextEdit() the data is via append(x ) are not updated, it is temporarily decided to force a redraw of the window.
For this, self.repaint() was used . self.update() didn't help.
Popen.communicate() didn't help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question