|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Killing command windows opened with os.system
I am running a python script that loads a command line based program. The command line based program is showing a propensity to stall.
I would like to be able to have python wait a few seconds and then kill the command line program and go to the next step. I have searched around but I cannot find the proper words if this has been discussed. Thanks, Matthew |
|
#2
|
||||
|
||||
|
Hi,
What you want as is not difficult but is platform dependent and you will probably have to make changes to the way you launch programs. ![]() os.system does not provide any process info or access to the application IO so it is very difficult to control. If you can get the process ID then it is possible to kill the process (see below). Other process launching methods like the popen2.Popen4 class or the os.spawnXX functions provide differing levels of process control. On *nix this will allow you to use the os.kill(processID,signal) function. If it is a Windows environment then You need to use WIN32 api's to do termination: Code:
import win32api win32api.TerminateProcess(processID,0) I hope this helped. grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
||||
|
||||
|
Quote:
I believe this is a more platform independant solution, although I'm not quite sure i've only been pythoning a week. Code:
import threading
thread_name = threading.Thread \
(group, target, name, args, kwargs)
thread_name.start();
(sleep or what have you)
thread_name.shutdown();
I still have this issue with the launcher replying slowly when the thread is running, however my thread launches its own threads, and it's a high memory high cpu-time application. -Mike "I have no use for your logic now, I'm programming" - Unknown
__________________
My blog on programming related things. Hopefully I won't bog it down with details on my life Apparently even computers have freudian slips. 0x4279 7465 204D 6521 |
|
#4
|
||||
|
||||
|
Mike,
It's true that if the program that is being run is another python module it should be possible to run it as a thread of the controlling program. However, I can't find a shutdown method in the threading documentation or source. The problem with threads is that you can only ask them nicely to terminate (Unless you know some under the hood code???). The new sub process module found in 2.4 might be useful here. grim ![]() |
|
#5
|
||||
|
||||
|
<looks a bit deeper at his code>
You're right. The .shutdown() method on my 'thread' was actually on a class surrounding the thread. The method went into the thread's function and set a shutdown variable. Sorry for the confusion. -Mike |
|
#6
|
||||
|
||||
|
No probs here
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Killing command windows opened with os.system |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|