473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Defunct Processes With subprocess.Pope n

Hi!

I'm currently writing a script which launches external programs, but it
keeps leaving zombie/defunct processes behind, until I kill the
launching script, which is a bit of a pain, as it's supposed to be a
daemon. The code I'm using is:

newPid = subprocess.Pope n( cmdLine[ 1: ], executable=cmdL ine[ 0 ],
close_fds=True ).pid

I've tried calling it using the shell=True flag, but that leaves a
zombie for the sh, instead. I'm not interested in any output, the only
thing I need returning, is the pid of the new process. I've tried using
spawn*, with the same results. Does anyone have any ideas?

Thanks.

J
Jul 19 '05 #1
2 10031
John Abel <ja***@plus.net > writes:
Hi!

I'm currently writing a script which launches external programs, but
it keeps leaving zombie/defunct processes behind, until I kill the
launching script, which is a bit of a pain, as it's supposed to be a
daemon. The code I'm using is:

newPid = subprocess.Pope n( cmdLine[ 1: ], executable=cmdL ine[ 0 ],
close_fds=True ).pid

I've tried calling it using the shell=True flag, but that leaves a
zombie for the sh, instead. I'm not interested in any output, the
only thing I need returning, is the pid of the new process. I've
tried using spawn*, with the same results. Does anyone have any ideas?


The processes are hanging around in a zombie state so the parent (or
someone) can get their exit status.

Try calling os.wait() until it returns the exit status for all the
processes you've started.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #2
Mike Meyer wrote:
John Abel <ja***@plus.net > writes:
Hi!

I'm currently writing a script which launches external programs, but
it keeps leaving zombie/defunct processes behind, until I kill the
launching script, which is a bit of a pain, as it's supposed to be a
daemon. The code I'm using is:

newPid = subprocess.Pope n( cmdLine[ 1: ], executable=cmdL ine[ 0 ],
close_fds=Tru e ).pid

I've tried calling it using the shell=True flag, but that leaves a
zombie for the sh, instead. I'm not interested in any output, the
only thing I need returning, is the pid of the new process. I've
tried using spawn*, with the same results. Does anyone have any ideas?


The processes are hanging around in a zombie state so the parent (or
someone) can get their exit status.

Try calling os.wait() until it returns the exit status for all the
processes you've started.

<mike

Ahh, OK. Thanks for that. Works now.

J
Jul 19 '05 #3

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

Similar topics

12
10978
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). ...
9
6474
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
7
4912
by: skunkwerk | last post by:
Hi, i'm trying to call subprocess.popen on the 'rename' function in linux. When I run the command from the shell, like so: rename -vn 's/\.htm$/\.html/' *.htm it works fine... however when I try to do it in python like so: p = subprocess.Popen(,stdout=subprocess.PIPE,stderr=subprocess.PIPE) print p.communicate()
4
2645
by: geoffbache | last post by:
Hi all, I've always wondered why os.kill isn't supported on Windows. I found a discussion somewhere from 2006 about this so it seems others have wanted it, but still nothing. So I have a half-baked solution involving calling "taskkill" on Windows Vista or "tskill" on Windows XP via the shell. I feel there has to be a better way. I'm also...
0
175
by: Gary Josack | last post by:
Cameron Simpson wrote: Use of the popen functions is generally discouraged since being deprecated for the subprocess module. Look at the subprocess module which will allow you to run processes and capture the output. The docstrings have good examples for how to use it.
1
9810
by: Mswed | last post by:
Hi all! I hope someone can help me out here! I'm running a GUI in python which is able to launch a separate python process that will run forever. In rare cases I will want to kill the launched process. Every time I do so, I end up with the process as defunct. Can anybody help me clean it up in a nice way? My code snippets: #Launching a...
1
2686
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 10:04:46 -0300, Gordon Maria <Maria.Gordon@afconsult.comescribi�: You should call os.waitpid() after killing the child process, to let the OS free the resources allocated to it. -- Gabriel Genellina
6
3797
by: Tim Arnold | last post by:
I have a bunch of processes to run and each one needs its own working directory. I'd also like to know when all of the processes are finished. (1) First thought was threads, until I saw that os.chdir was process- global. (2) Next thought was fork, but I don't know how to signal when each child is finished. (3) Current thought is to break...
1
8605
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output parameters that are passed and captured from this exe. When I use the class outside of a service using either subprocess.Popen or os.popen2 work...
0
7920
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...
0
7849
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...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
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...
0
5394
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...
0
3844
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...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
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.