Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'else:': 0.03; 'subject:Python': 0.04; 'repeatedly': 0.04; 'responding': 0.04; 'wed,': 0.04; 'high-level': 0.05; 'snippet': 0.07; 'finishes': 0.09; 'pm,': 0.11; 'written': 0.12; 'def': 0.13; 'wrote:': 0.14; 'executed,': 0.16; 'invoking': 0.16; 'prompt?': 0.16; 'run(self):': 0.16; 'shell=true)': 0.16; 'subject:Programming': 0.16; 'subject:Thread': 0.16; '\xa0def': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'meant': 0.18; 'command': 0.19; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'manually': 0.22; 'trying': 0.23; 'statement,': 0.23; 'works.': 0.23; 'runs': 0.24; "didn't": 0.25; "wasn't": 0.25; 'script': 0.26; "i'm": 0.26; 'chris': 0.27; 'function': 0.27; 'work.': 0.27; 'message-id:@mail.gmail.com': 0.28; 'definition': 0.29; 'depends': 0.29; 'class': 0.29; 'instead,': 0.29; "won't": 0.30; 'invoke': 0.31; 'it.': 0.31; 'to:addr:python-list': 0.32; '\xa0\xa0\xa0': 0.33; 'skip:" 10': 0.34; 'there': 0.35; 'print': 0.35; 'apologies': 0.35; 'some': 0.37; 'should': 0.37; 'received:209.85': 0.37; 'run': 0.37; 'thread': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'skip:" 20': 0.38; 'active': 0.39; 'explain': 0.39; 'skip:s 30': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'how': 0.39; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'overall': 0.64; 'intend': 0.68; '11,': 0.77; 'dies.': 0.84; 'intentions': 0.84; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; 'immediately,': 0.91; 'minute.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=ZnEcPM4tRVq/CcTU7vSqUp00fapiGXbqvLwd6OPycio=; b=kOrkv/PuVmhvg9wzjzjrYN8RNHaPQCD6+PYx4v8o3K9uUz57dbe548I99I1IaeaUGm jp+O9B772cCTh8VjCcYL4I29YNke9QGHI+ouG68dtSlwNKJX0yeU9QzAGrB+DikT/1/C IxdhPe6/Y4RQWKWl6jV5V89AXMth34WVR4Vrs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=dblKQQ8q14hDvTE5+bYbkBuBlg00AhRFyxfCq00jh9lHHcko5XEMsFmRCU1aw9OeXW SLXwZqbtUB0En5EPwv+DzR0ckjIUCMNRAzdLwODHPcbrhKWR/sDd46yC298Nls09Qfld 4vK7YRs9n7qIznsVI/8pWIuMYMdxaGEaFRa6I= MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 11 May 2011 18:46:36 +1000 Subject: Re: NewBie Doubt in Python Thread Programming From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305103600 news.xs4all.nl 81483 [::ffff:82.94.164.166]:39664 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5099 I'm responding to this on-list on the assumption that this wasn't meant to be private; apologies if you didn't intend for this to be the case! On Wed, May 11, 2011 at 6:38 PM, vijay swaminathan wro= te: > so If i understand correctly, once the run method of the thread is execut= ed, > the thread is no more alive. Once run() finishes executing, the thread dies. > Actually, I'm trying to invoke a command prompt to run some script and as > long as the script runs on the command prompt, I would like to have the > thread alive. But according to your statement, the thread would die off > after invoking the command prompt. is there a way to keep the thread acti= ve > till I manually close the command prompt? That depends on how the "invoke command prompt" function works. > A snippet of the code written is: > # Thread definition > class RunMonitor(QThread): > =A0=A0=A0 def __init__(self, parent=3DNone): > =A0=A0=A0=A0=A0=A0=A0 QThread.__init__(self) > =A0=A0=A0 def run(self): > =A0=A0=A0=A0=A0=A0=A0 print 'Invoking Command Prompt..........' > =A0=A0=A0=A0=A0=A0=A0 subprocess.call(["start", "/DC:\\Scripts", > "scripts_to_execute.bat"], shell=3DTrue) > > =A0def sendData(self): > > =A0=A0=A0=A0=A0=A0=A0 if self.run_timer: > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 run_monitor_object =3D RunMonitor() > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print 'Starting the thread...........' > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 run_monitor_object.start() > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.run_timer =3D False > > =A0=A0=A0=A0=A0=A0=A0 if run_monitor_object.isAlive(): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print 'Thread Alive...' > =A0=A0=A0=A0=A0=A0=A0 else: > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print 'Thread is Dead....' > subprocess.call() will return immediately, so this won't work. But if you use os.system() instead, then it should do as you intend. > to check the status of the thread repeatedly I have the QTimer which woul= d > call the self.sendData() for every minute. > > =A0=A0=A0=A0=A0=A0=A0 self.timer =3D QTimer() > =A0=A0=A0=A0=A0=A0=A0 self.timer.connect(self.timer, SIGNAL("timeout()"),= self.sendData) > =A0=A0=A0=A0=A0=A0=A0 self.timer.start(1000) I'm not really sure what your overall goal is. Can you explain more of your high-level intentions for this program? There may be a much easier way to accomplish it. Chris Angelico