[PyQt] reading from stdin breaks on .close()

Markus Straub code at ravage.at
Thu Jun 12 16:40:24 BST 2008


Hello,

I noticed that a program which is reading data from stdin will stop doing so 
as soon as .close() has been evoked onto a PyQt4-element. Does anybody know 
what is exactly happening (broken pipe? pipe output redirectt?) and if this 
is a known and valid behaviour? It seems to me that this shouldn't happen.

The following test-code demonstrates this behaviour:

#!/usr/bin/env python

import os, sys, threading

try:
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
except:
    print "PyQt4 is required"

class MsgReader( QApplication ):
    def __init__( self, args ):
        QApplication.__init__( self, args )
        print "Type any word to echo it, \
type \"close\" to demonstrate the strange behaviour"
        self.stdinReader = threading.Thread( target = self.readStdin )
        self.stdinReader.start()

    def readStdin( self ):
        while 1:
            line = sys.stdin.readline()
            if not line:
                break
            line = line.rstrip()
            if(line == "close"):
                dialog = QDialog()
                dialog.show()
                dialog.close()
            print "echo:", line

def main( ):
    app = MsgReader( sys.argv )
    app.exec_()

if __name__ == "__main__":
    mainapp = threading.Thread(target=main)
    mainapp.start()


(The stdin-behaviour is the same as with the program where i stumbled over 
this peculiar problem, even if the QDialog won't show and the program 
complains about "QPixmap: It is not safe to use pixmaps outside the GUI 
thread")

Best,
Markus


More information about the PyQt mailing list