Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 20th, 2004, 04:57 PM
ouchitburns ouchitburns is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 ouchitburns User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 21st, 2004, 04:59 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #3  
Old October 21st, 2004, 09:33 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,272 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 h 12 m 48 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
Quote:
Originally Posted by Grim Archon
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.

grim


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

Reply With Quote
  #4  
Old October 21st, 2004, 10:39 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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

Reply With Quote
  #5  
Old October 21st, 2004, 11:28 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,272 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 h 12 m 48 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
<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

Reply With Quote
  #6  
Old October 21st, 2004, 11:46 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
No probs here

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Killing command windows opened with os.system


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT