[PyQt] QProcess hangup using PyQt + threads

Denis RIVIERE denis.riviere at cea.fr
Fri Feb 26 13:14:51 GMT 2010


Le vendredi 26 février 2010, Phil Thompson a écrit :
> On Fri, 26 Feb 2010 12:08:58 +0000, Phil Thompson
>
> <phil at riverbankcomputing.com> wrote:
> >
> > Unless you can provide me with a test case you'll have to experiment...
> >
> > Try adding...
> >
> >     pthread_atfork(NULL, NULL, PyOS_AfterFork);
> >
> > ...after the call to PyEval_InitThreads() in siplib.c.
>
> An alternative (which I may be more comfortable with) is to add the
> /HoldGIL/ annotation to all QProcess.start() overloads. However the
> asynchronous nature of process starts may mean it has no effect.
>
> Phil

I will try the pthread_atfork() thing, which seems to me to be safer. While I 
recompile sip and PyQt (I was using the linux distribution compiled version), 
here is a test case, which holds after a while:


#!/usr/bin/env python

import threading
from PyQt4 import QtCore

def theotherthread():
    print 'theotherthread'
    while True:
        a = 'turlute'

def processExited():
    print 'processExited'

def readStdout():
    global qprocess
    print qprocess.readAllStandardOutput()

def readStderr():
    global qprocess
    print qprocess.readAllStandardError()

thread1 = threading.Thread( target=theotherthread )
thread1.start()
while True:
    qprocess = QtCore.QProcess()
    qprocess.connect( qprocess,
                      QtCore.SIGNAL( 'finished( int, 
QProcess::ExitStatus )' ),
                      processExited )
    qprocess.connect( qprocess, QtCore.SIGNAL( 'readyReadStandardOutput()' ),
                      readStdout  )
    qprocess.connect( qprocess, QtCore.SIGNAL( 'readyReadStandardError()' ),
                      readStderr  )
    qprocess.start( 'echo', [ 'totototototototo' ] )
    qprocess.waitForFinished(-1)

--
Denis



More information about the PyQt mailing list