Python subprocess question

Roger rdcollum at gmail.com
Tue Jan 6 19:07:04 CET 2009


On Jan 6, 7:46 am, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> "Alexi Zuo" <alexi.... at gmail.com> wrote:
> > Hi everyone,
>
> > Here I have a simple program which starts a thread and the thread use
> > Popen to execute a shell cmd which needs a long time.  I want to stop
> > the thread once I type "ctrl+C" (KeyboardInterrupt). But in fact this
> > program enters a dead loop. Can anyone tell me what is wrong?
>
> The KeyboardInterrupt exception is being raised in your main thread which
> doesn't handle it so it just terminates. Your child thread isn't marked as
> a daemon thread so the program won't exit until the child thread has also
> terminated.

I've been recently working with threads for the first time and I've
been unclear on the setDaemon flag though I've sifted through the
documentation for a clear answer (most likely my reading comprehension
has failed me and not the documentation).  I think I had the notion of
that flag backwards.  .setDaemon(True) means the thread gets destroyed
when the program exits and default .setDaemon(False) means that the
thread continues to process even when the main program is gone?



More information about the Python-list mailing list