473,320 Members | 1,947 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,320 software developers and data experts.

Copying file descriptors

I am using the following code. It is used to spawn a new process (using
popen) and to change the file handles so that subsequent writes to
standard output with printf goes into this child process standard input.
import os

child_stdin = os.popen("cat -", "w")
old_stdout = os.dup(1)
os.close(child_stdin.fileno())

print "foo"

os.dup2(old_stdout, 1)
os.close(old_stdout)

It works. But the results is:
close failed: [Errno 9] Bad file descriptor
when I am using python 2.4. Note that python 2.3 did not output such an
error.

I am guessing that upon ending the script, python tries to close
child_stdin file object, whereas the underlying file descriptor has
already been closed. Thus the error.

Does anyone knows what to do to avoir this error message?

Thanks
Didier
Oct 6 '06 #1
0 1053

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

Similar topics

2
by: François Pinard | last post by:
This question is a bit technical, but hopefully, this list will offer me good hints or nice solutions. Happily enough for me, it often does! :-) I would need to recognise and play with...
5
by: John Marshall | last post by:
Hi, Does anyone see a problem with doing: data = file("tata").read() Each time this is done, I see a new file descriptor allocated (Linux) but not released. 1) Will there ever be a point...
5
by: JG | last post by:
Hi all, Does anyone know how the implementations on Linux and Windows handle synchronization between a read and write FD open to the same file. For example, if I have 2 FD open to file X.txt. ...
36
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): ...
0
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
5
by: yinglcs | last post by:
I have a c/c++ program in linux. I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file...
8
ashitpro
by: ashitpro | last post by:
Understanding Ext-2 file system:chapter 1 The first block in each Ext2 partition is never managed by the Ext2 filesystem, because it is reserved for the partition boot sector. The rest of the...
2
by: DJ Dharme | last post by:
Hi all, I am writing a multi-threaded application in c++ running on solaris. I have a file which is updated by a single thread by appending data into the file and at same time the other threads...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.