[PyQt] Avoiding freeze of the application

Roberto Alsina ralsina at kde.org
Sat Feb 7 16:22:08 GMT 2009


On Saturday 07 February 2009 13:53:27 Geert Vancompernolle wrote:
> I currently started the one shot timer just before I launched the
> subprocess call, but I see that the one shot timer is also blocked by
> the subprocess call.  So, that doesn't do what I in fact want to do.

Check the docs for subprocess.call:

    call(*popenargs, **kwargs):
        Run command with arguments.  Wait for command to complete, then
        return the returncode attribute.

Since it will wait right there until the process ends, your app blocks.

> My questions:
>
> 1. How can I "decouple" the subprocess call?

Check the threading or processing modules. Or use Popen instead of call.

> 2. How can I forcefully stop a subprocess call (that should be the case
> if my one shot timer elapses after 10 seconds, and the subprocess call
> is not returned yet)?

You kill it. However, if you start it blocking, you can't. If you create the 
subprocess using Popen, then you can poll() it, and then, if needed, get its 
pid and kill it using os.kill.

> 3. What's the best approach to achieve the above requirements?  Using a
> kind of a state machine, where I first start the subprocess call
> (decoupled), then start the one shot timer, change the state and then
> check in that state if the subprocess call has indeed ended?  And if
> not, forcefully stop the subprocess call?

Yes, I think.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090207/6a39d505/attachment.html


More information about the PyQt mailing list