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


Groups > comp.lang.python > #5099 > unrolled thread

Re: NewBie Doubt in Python Thread Programming

Started byChris Angelico <rosuav@gmail.com>
First post2011-05-11 18:46 +1000
Last post2011-05-11 18:46 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#5099 — Re: NewBie Doubt in Python Thread Programming

FromChris Angelico <rosuav@gmail.com>
Date2011-05-11 18:46 +1000
SubjectRe: NewBie Doubt in Python Thread Programming
Message-ID<mailman.1396.1305103600.9059.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web