[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Avoiding freeze of the application
From:       Roberto Alsina <ralsina () kde ! org>
Date:       2009-02-07 16:22:08
Message-ID: 200902071422.09232.ralsina () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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.


[Attachment #5 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style \
type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Droid Sans \
Mono'; font-size:8pt; font-weight:400; font-style:normal;">On Saturday 07 February 2009 13:53:27 Geert \
Vancompernolle wrote:<br> &gt; I currently started the one shot timer just before I launched the<br>
&gt; subprocess call, but I see that the one shot timer is also blocked by<br>
&gt; the subprocess call.  So, that doesn't do what I in fact want to do.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Check the docs for subprocess.call:<br> \
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
                -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>    call(*popenargs, \
                **kwargs):<br>
        Run command with arguments.  Wait for command to complete, then<br>
        return the returncode attribute.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Since it will wait right there until the \
process ends, your app blocks.<br> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>&gt; \
My questions:<br> &gt;<br>
&gt; 1. How can I "decouple" the subprocess call?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Check the threading or processing \
modules. Or use Popen instead of call.<br> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"><br></p>&gt; 2. How can I forcefully stop a subprocess call (that should be the \
case<br> &gt; if my one shot timer elapses after 10 seconds, and the subprocess call<br>
&gt; is not returned yet)?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>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.<br> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"><br></p>&gt; 3. What's the best approach to achieve the above requirements?  Using \
a<br> &gt; kind of a state machine, where I first start the subprocess call<br>
&gt; (decoupled), then start the one shot timer, change the state and then<br>
&gt; check in that state if the subprocess call has indeed ended?  And if<br>
&gt; not, forcefully stop the subprocess call?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Yes, I think.<br> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p></body></html>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic