473,786 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can Python kill a child process that keeps on running?

Suppose we spawn a child process with Popen. I'm thinking of an
executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going
and going. Does Python have any way to kill it?

This is not hypothetical; I'm doing it now, and it's working pretty
well, but I would like to be able to handle this run-on condition. I'm
using Windows 2000, but I want my program to be portable to linux.

Thanks

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
May 1 '06
10 3006
Using Pywin32 (obviously not cross platform):

import win32api,win32c on
h=win32api.Open Process(win32co n.PROCESS_TERMI NATE,False, <pid>)
win32api.Termin ateProcess(h, <exit code>)

Roger

"I. Myself" <No*****@Spam.n one> wrote in message news:g0x5g.1046 39$7a.102977@pd 7tw1no...
Suppose we spawn a child process with Popen. I'm thinking of an executable file, like a compiled C program.
Suppose it is supposed to run for one minute, but it just keeps going and going. Does Python have any way to kill it?

This is not hypothetical; I'm doing it now, and it's working pretty well, but I would like to be able to handle this run-on
condition. I'm using Windows 2000, but I want my program to be portable to linux.

Thanks

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 6 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8765
by: klappnase | last post by:
Hello, everyone, I am running python2.2.2 on a linux box. I want to call a shell command and get the PID of this child process so I have the possibility to abort the child process while it is still running. I tried the popen2 module for that: self.pp = popen2.Popen3(cmd)
6
7052
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with os.kill(self.popen.pid, signal.SIGTERM) Everything works fine on MacOSX. However, I'm doing a port to Solaris (so I can run it on my web site) and find that the child processes are not stopping! Solaris is creating TWO new processes: one for the SHELL...
2
1544
by: Tor Erik Sønvisen | last post by:
Hi. From my Python-program I spawn a new process. When using P_NOWAIT spawnl returns the pid but in windows it returns a process handle. Later I want to kill this process. How can I do this when I only have the process handle? -tores-
2
2060
by: Sarir Khamsi | last post by:
I would like to start a child process (like w/ popen3(), or some such) and then be able to interrupt it by sending it a control-c. How do I do that in Python? Is there a better way to gracefully halt a child process? Is there a more cross-platform way to start a child process (popen() is only on UNIX/Win32)? Thanks. Sarir
1
3479
by: Alexander N. Spitzer | last post by:
I am trying to write a program that will fork a process, and execute the given task... the catch is that if it runs too long, I want to clean it up. this seemed pretty straight forward with a single executable being run from the fork. The problem I am having now is that if I call a shell scripts, then lets say calls "xterm &", after the timeout has occurred, I kill the shell script, but the xterm is still running... I cannot seem to kill...
0
6132
by: lynn | last post by:
I'm doing a c# asp.net web application. It create a process "A" to excute an .exe file. This exe file is compiled from c++. In this exe file it will create another new process "B" to excute another .exe file. (This one is VB, but I think this doesn't matter). What I want to do is when I kill the first process "A" from c#(usill kill() function) I want to kill the child process "B" at the same time. If all is in c++ maybe I can figure it out...
1
1132
by: tcbrock | last post by:
I'm running Visual Studio 97 (vc++ 5.0) on Windows XP SP2 and when I run my program from inside the development environment, and then I quit it, it goes back to VC, but sometimes if I hit CTRL-ALT-DEL and look at my processes running, there is my program! Which can stop it from linking or running successfully until I kill it in there. Has anyone else seen this? It's just started happening to me in the last few months.
0
2190
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle = ProcessWindowStyle.Hidden
4
4851
by: Ashit Vora | last post by:
Hi, My query is... I have a parent process which forks a child process to perform certain task. I wish to terminate the child process after certain amount of time (say 60 secs). Since I dont wish to leave any zombie process, I need to notify the Child that it has to terminate now. The parent can terminate only after all the child processes have
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.