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


Groups > comp.lang.python > #5099

Re: NewBie Doubt in Python Thread Programming

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 <rosuav@gmail.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; '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 <BANLkTin7fq7ybKq94ZUs-7X8dLu7_UFnrQ@mail.gmail.com>
References <BANLkTikr8fu1sDrfu2a-wyEN_KpVVNCdew@mail.gmail.com> <BANLkTik_ZLvgUVuttiGKQshLmnkU_Mvk+g@mail.gmail.com> <BANLkTin7fq7ybKq94ZUs-7X8dLu7_UFnrQ@mail.gmail.com>
Date Wed, 11 May 2011 18:46:36 +1000
Subject Re: NewBie Doubt in Python Thread Programming
From Chris Angelico <rosuav@gmail.com>
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 <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.1396.1305103600.9059.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 <swavijay@gmail.com> wrote:
> so If i understand correctly, once the run method of the thread is executed,
> 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 active
> 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):
>     def __init__(self, parent=None):
>         QThread.__init__(self)
>     def run(self):
>         print 'Invoking Command Prompt..........'
>         subprocess.call(["start", "/DC:\\Scripts",
> "scripts_to_execute.bat"], shell=True)
>
>  def sendData(self):
>
>         if self.run_timer:
>             run_monitor_object = RunMonitor()
>             print 'Starting the thread...........'
>             run_monitor_object.start()
>             self.run_timer = False
>
>         if run_monitor_object.isAlive():
>             print 'Thread Alive...'
>         else:
>             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 would
> call the self.sendData() for every minute.
>
>         self.timer = QTimer()
>         self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData)
>         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

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


Thread

Re: NewBie Doubt in Python Thread Programming Chris Angelico <rosuav@gmail.com> - 2011-05-11 18:46 +1000

csiph-web