Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11904

Re: Help on PyQt4 QProcess

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <phil@riverbankcomputing.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'thread,': 0.04; 'prints': 0.07; 'semantic': 0.07; 'python': 0.08; 'be:': 0.09; 'properly.': 0.09; 'slot': 0.09; 'subprocess': 0.09; 'output': 0.10; 'exception': 0.12; 'gui': 0.13; 'argument': 0.15; '"0"': 0.16; 'lambda': 0.16; 'occurs.': 0.16; 'prototype,': 0.16; 'pythonic': 0.16; 'received:openhosting.com': 0.16; 'received:user.openhosting.com': 0.16; 'skip:\xc2 30': 0.16; 'skip:\xc2 40': 0.16; 'synchronous': 0.16; '\xc2\xa0if': 0.16; '\xc2\xa0you': 0.16; 'cc:addr:python-list': 0.16; 'syntax': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'subject:Help': 0.17; 'int': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply- To:1': 0.22; '-0700': 0.23; 'aug': 0.24; 'code': 0.25; 'helpful': 0.26; 'function': 0.27; 'all,': 0.28; 'correct': 0.28; 'import': 0.28; 'fix': 0.29; 'cc:addr:python.org': 0.30; '(depending': 0.30; 'accidentally': 0.30; 'arguments.': 0.30; 'carl': 0.30; 'second,': 0.30; 'semantics': 0.30; 'throwing': 0.30; 'thanks': 0.30; 'adds': 0.32; 'error.': 0.32; 'does': 0.32; 'instead': 0.33; 'that,': 0.33; 'calling': 0.33; 'header:User-Agent:1': 0.34; 'force': 0.34; 'rather': 0.35; 'switch': 0.35; 'external': 0.35; 'object': 0.35; 'connection': 0.36; 'fri,': 0.36; 'skip:" 10': 0.36; '8bit%:6': 0.37; 'example,': 0.37; 'friday,': 0.37; 'using': 0.37; 'run': 0.37; 'but': 0.37; 'two': 0.37; 'signal': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'finished': 0.39; 'ok,': 0.39; 'enough': 0.39; 'goes': 0.39; "there's": 0.39; 'why': 0.39; 'case': 0.39; 'might': 0.40; "it's": 0.40; 'more': 0.60; 'your': 0.61; 'order': 0.62; 'dear': 0.63; 'accepts': 0.64; 'guarantee': 0.66; 'august': 0.70; 'unnecessary': 0.73; 'skip:\xc2 10': 0.74; 'modern,': 0.91
X-Virus-Scanned Debian amavisd-new at rvrbank1.user.openhosting.com
MIME-Version 1.0
Date Sat, 20 Aug 2011 09:36:02 +0100
From Phil Thompson <phil@riverbankcomputing.com>
To Edgar Fuentes <fuentesej@gmail.com>
Subject Re: Help on PyQt4 QProcess
Organization Riverbank Computing Limited
In-Reply-To <fc9a4e92-6975-48ac-b7d9-363be6f7a26d@m18g2000vbl.googlegroups.com>
References <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <mailman.229.1313777088.27778.python-list@python.org> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> <fc9a4e92-6975-48ac-b7d9-363be6f7a26d@m18g2000vbl.googlegroups.com>
X-Sender phil@riverbankcomputing.com
User-Agent RoundCube Webmail/0.3.1
Content-Transfer-Encoding 8bit
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.254.1313829368.27778.python-list@python.org> (permalink)
Lines 91
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313829368 news.xs4all.nl 23978 [2001:888:2000:d::a6]:56023
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11904

Show key headers only | View raw


On Fri, 19 Aug 2011 14:32:12 -0700 (PDT), Edgar Fuentes
<fuentesej@gmail.com> wrote:
> On Aug 19, 4:21 pm, Carl Banks <pavlovevide...@gmail.com> wrote:
>> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote:
>> > On Aug 19, 1:56 pm, Phil Thompson
>> >  wrote:
>> > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes
>> > > <fuen...@gmail.com> wrote:
>> > > > Dear friends,
>>
>> > > > I need execute an external program from a gui using PyQt4, to
avoid
>> > > > that hang the main thread, i must connect the signal
>> > > > "finished(int)"
>> > > > of a QProcess to work properly.
>>
>> > > > for example, why this program don't work?
>>
>> > > >    from PyQt4.QtCore import QProcess
>> > > >    pro = QProcess() # create QProcess object
>> > > >    pro.connect(pro, SIGNAL('started()'), lambda
>> > > > x="started":print(x))        # connect
>> > > >    pro.connect(pro, SIGNAL("finished(int)"), lambda
>> > > > x="finished":print(x))
>> > > >    pro.start('python',['hello.py'])        # star hello.py
program
>> > > > (contain print("hello world!"))
>> > > >    timeout = -1
>> > > >    pro.waitForFinished(timeout)
>> > > >    print(pro.readAllStandardOutput().data())
>>
>> > > > output:
>>
>> > > >    started
>> > > >    0
>> > > >    b'hello world!\n'
>>
>> > > > see that not emit the signal finished(int)
>>
>> > > Yes it is, and your lambda slot is printing "0" which is the return
>> > > code
>> > > of the process.
>>
>> > > Phil
>>
>> > Ok, but the output should be:
>>
>> >     started
>> >     b'hello world!\n'
>> >     finished
>>
>> > no?.
>>
>> > thanks Phil
>>
>> Two issues.  First of all, your slot for the finished function does not
>> have the correct prototype, and it's accidentally not throwing an
>> exception because of your unnecessary use of default arguments.
 Anyway,
>> to fix that, try this:
>>
>> pro.connect(pro, SIGNAL("finished(int)"), lambda v,
>> x="finished":print(x))
>>
>> Notice that it adds an argument to the lambda (v) that accepts the int
>> argument of the signal.  If you don't have that argument there, the int
>> argument goes into x, which is why Python prints 0 instead of
"finished".
>>
>> Second, processess run asynchrously, and because of line-buffering, IO
>> can output asynchronously, and so there's no guarantee what order
output
>> occurs.  You might try calling the python subprocess with the '-u'
switch
>> to force unbuffered IO, which might be enough to force synchronous
output
>> (depending on how signal/slot and subprocess semantics are
implemented).
>>
>> Carl Banks
> 
> Thanks Carl, your intervention was very helpful for me, this solve my
> semantic error. I need to study more about signal/slots and process.

In which case you should look at the modern, Pythonic connection syntax
rather than the old one...

    pro.started.connect(lambda: print("started"))
    pro.finished.connect(lambda: print("finished"))

Phil

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help on PyQt4 QProcess Edgar Fuentes <fuentesej@gmail.com> - 2011-08-19 10:15 -0700
  Re: Help on PyQt4 QProcess Phil Thompson <phil@riverbankcomputing.com> - 2011-08-19 18:56 +0100
    Re: Help on PyQt4 QProcess Edgar Fuentes <fuentesej@gmail.com> - 2011-08-19 12:55 -0700
      Re: Help on PyQt4 QProcess Carl Banks <pavlovevidence@gmail.com> - 2011-08-19 13:21 -0700
        Re: Help on PyQt4 QProcess Edgar Fuentes <fuentesej@gmail.com> - 2011-08-19 14:32 -0700
          Re: Help on PyQt4 QProcess Phil Thompson <phil@riverbankcomputing.com> - 2011-08-20 09:36 +0100
            Re: Help on PyQt4 QProcess Edgar Fuentes <fuentesej@gmail.com> - 2011-08-22 10:43 -0700

csiph-web