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


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

Re: Need Assistance on this program.

Started byTim Golden <mail@timgolden.me.uk>
First post2011-05-12 11:38 +0100
Last post2011-05-12 11:38 +0100
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: Need Assistance on this program. Tim Golden <mail@timgolden.me.uk> - 2011-05-12 11:38 +0100

#5225 — Re: Need Assistance on this program.

FromTim Golden <mail@timgolden.me.uk>
Date2011-05-12 11:38 +0100
SubjectRe: Need Assistance on this program.
Message-ID<mailman.1459.1305196686.9059.python-list@python.org>
On 12/05/2011 11:29, vijay swaminathan wrote:

<... snippet from code ...>
   print 'Invoking Command Promptt..............'
         #subprocess.call(["start", "/DC:\\PerfLocal_PAL", 
"scripts_to_execute.bat"], shell=True)
         subprocess.call(["start", "C:\\windows\\system32\\cmd.exe"], 
shell = True)
         self.status()
</snippet>

If you want to use start, use start /wait.

But you don't have to:

<code>
import threading
import time
import subprocess

def run_command (command):
   #
   # .call is shorthand for: start process and wait
   # CREATE_NEW_CONSOLE prevents it from getting messed
   #  up with the Python console
   #
   subprocess.call (
     [command],
     creationflags=subprocess.CREATE_NEW_CONSOLE
   )

t = threading.Thread (target=run_command, args=("cmd.exe",))
t.start ()

while t.is_alive ():
   print "alive"
   time.sleep (0.5)

print "Thread is dead"

</code>

TJG

[toc] | [standalone]


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


csiph-web