473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

os.popen() interferes with os.fork()?

On Linux I get a "close failed: [Errno 10] No child processes" msg for
each fork. But only if I have a pipe open. I don't understand the
connection between the popen and the forks. Am I doing something
wrong?
#! /usr/bin/env python

import os
import sys
import time

p = os.popen('top -b -d1')

n = 3
t1 = time.time()
for i in range(n):
pid = os.fork()
if pid == 0:
sys.exit(0)
delay = time.time() - t1
print 'rate: %.1f fork/sec' % (n/delay)
Aug 25 '08 #1
1 1964
JohnMudd <Jo*******@gmail.comwrites:
On Linux I get a "close failed: [Errno 10] No child processes" msg
for each fork. But only if I have a pipe open. I don't understand
the connection between the popen and the forks. Am I doing
something wrong?
Yes: don't use sys.exit, use os._exit. This is not specific to
Python; in C you'd also need to use _exit(2) in preference to exit(3)
to exit a forked process.

With sys.exit(0) changed to os._exit(0), the program outputs:

rate: 2962.1 fork/sec
Aug 25 '08 #2

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

Similar topics

3
by: Mark Roach | last post by:
I am using the daemonize (double-fork) code from the cookbook, and have bumped into a strange issue. This is what my program is doing: def main(): ... useful things ... os.popen('/usr/bin/lp -d...
10
by: Nick Craig-Wood | last post by:
I'm trying to avoid using shell metacharacters in os.popen in a portable fashion. os.popen() only seems to take a string as the command which would need tricky quoting. os.popen2() can take a...
2
by: christiancoder | last post by:
Is anybody else getting the following error with the Popen object in cygwin? The code works fine in windows and linux. File "d:\atg\personal\python\buildroot\util.py", line 100, in System pipe =...
7
by: Jacek Popławski | last post by:
I am still in the process of creating my script which will run command received from socket. My scripts works perfectly on Linux, but doesn't work on QNX! File "/usr/lib/python2.4/popen2.py",...
17
by: bastiaannaber | last post by:
I am trying to write a program which uses popen but I have a problem. I want to detect if the program I call with popen has ended. For example: #include <stdio.h> #include <sys/types.h>...
1
by: Michele Simionato | last post by:
I was experimenting with subprocess.Popen with the following script: $ cat Popen_ex.py import sys, subprocess po = subprocess.Popen(, stdout=subprocess.PIPE, bufsize=0) for line in po.stdout:...
3
by: Rob Hoelz | last post by:
Hello everyone, I've been trying to roll my own popen(), but I've run into problems. Would anyone care to look at my code and tell me what I'm doing wrong? Here's my code: #include...
1
by: Jonathan Amsterdam | last post by:
This is a bug in python 2.4 under Linux 2.6. I occasionally see subprocess.Popen() fail to return, and I have finally figured out roughly what's going on. It involves the GC and stderr. 1....
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.