Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5099
| References | <BANLkTikr8fu1sDrfu2a-wyEN_KpVVNCdew@mail.gmail.com> <BANLkTik_ZLvgUVuttiGKQshLmnkU_Mvk+g@mail.gmail.com> <BANLkTin7fq7ybKq94ZUs-7X8dLu7_UFnrQ@mail.gmail.com> |
|---|---|
| Date | 2011-05-11 18:46 +1000 |
| Subject | Re: NewBie Doubt in Python Thread Programming |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1396.1305103600.9059.python-list@python.org> (permalink) |
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
Re: NewBie Doubt in Python Thread Programming Chris Angelico <rosuav@gmail.com> - 2011-05-11 18:46 +1000
csiph-web