Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > closing stdin, stdout and stderr

Reply
Thread Tools

closing stdin, stdout and stderr

 
 
Martijn Brouwer
Guest
Posts: n/a
 
      12-26-2005
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn



 
Reply With Quote
 
 
 
 
Robin Becker
Guest
Posts: n/a
 
      12-26-2005
Martijn Brouwer wrote:
> I am writing a unix daemon in python, so I want to close stdin, stdout
> and stderr.
> My first attempt was to the standard file descriptors using their
> close() methods. After closing stdout, I could not print anymore, so
> this seemed to work. However, later I noticed that they were not really
> closed. When I close them using os.close(), it did work.
> What is the difference between these two methods and what is the reason
> behind it? It took me a day to find out why I could not log out after
> starting the daemon.
>
> Martijn
>
>
>

I've had excellent results with variants of the cookbook entry at

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731

--
Robin Becker
 
Reply With Quote
 
 
 
 
Robin Becker
Guest
Posts: n/a
 
      12-26-2005
Robin Becker wrote:
> Martijn Brouwer wrote:
>
>> I am writing a unix daemon in python, so I want to close stdin, stdout
>> and stderr.
>> My first attempt was to the standard file descriptors using their
>> close() methods. After closing stdout, I could not print anymore, so
>> this seemed to work. However, later I noticed that they were not really
>> closed. When I close them using os.close(), it did work.
>> What is the difference between these two methods and what is the reason
>> behind it? It took me a day to find out why I could not log out after
>> starting the daemon.
>>
>> Martijn
>>
>>
>>

> I've had excellent results with variants of the cookbook entry at
>
> http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
>

but perhaps you're using a non unix OS, which will make that recipe wrong.

--
Robin Becker
 
Reply With Quote
 
Martijn Brouwer
Guest
Posts: n/a
 
      12-27-2005
On Mon, 2005-12-26 at 23:13 +0000, Robin Becker wrote:
> Martijn Brouwer wrote:
> > I am writing a unix daemon in python, so I want to close stdin, stdout
> > and stderr.
> > My first attempt was to the standard file descriptors using their
> > close() methods. After closing stdout, I could not print anymore, so
> > this seemed to work. However, later I noticed that they were not really
> > closed. When I close them using os.close(), it did work.
> > What is the difference between these two methods and what is the reason
> > behind it? It took me a day to find out why I could not log out after
> > starting the daemon.
> >
> > Martijn
> >
> >
> >

> I've had excellent results with variants of the cookbook entry at
>
> http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
>


I read this one, which was the reason that I tried os.close instead of
sys.stdXXX.close(). But I would like to know why it does not close a
file discriptor is I call its close method().


Martijn

--
Martijn Brouwer <(E-Mail Removed)>

 
Reply With Quote
 
Martijn Brouwer
Guest
Posts: n/a
 
      12-27-2005
On Mon, 2005-12-26 at 23:15 +0000, Robin Becker wrote:
> Robin Becker wrote:
> > Martijn Brouwer wrote:
> >
> >> I am writing a unix daemon in python, so I want to close stdin, stdout
> >> and stderr.
> >> My first attempt was to the standard file descriptors using their
> >> close() methods. After closing stdout, I could not print anymore, so
> >> this seemed to work. However, later I noticed that they were not really
> >> closed. When I close them using os.close(), it did work.
> >> What is the difference between these two methods and what is the reason
> >> behind it? It took me a day to find out why I could not log out after
> >> starting the daemon.
> >>
> >> Martijn
> >>
> >>
> >>

> > I've had excellent results with variants of the cookbook entry at
> >
> > http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
> >

> but perhaps you're using a non unix OS, which will make that recipe wrong.


Well, I am writing a unix daemon

Martijn


 
Reply With Quote
 
Donn Cave
Guest
Posts: n/a
 
      12-27-2005
In article <(E-Mail Removed)>,
Martijn Brouwer <(E-Mail Removed)> wrote:
....
> I read this one, which was the reason that I tried os.close instead of
> sys.stdXXX.close(). But I would like to know why it does not close a
> file discriptor is I call its close method().


They're special. I suppose because of internal dependencies - last
chance exception handler etc. - they are created without a close
function, internally, so close() has no effect. I don't know if it
really makes any sense, since anyway one may close the file descriptors
directly as you did.

Donn Cave, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
subprocess.Popen and ordering writes to stdout and stderr Chris Withers Python 1 12-18-2009 06:57 PM
stdout and stderr to console and file simultaneously ids C Programming 4 04-14-2009 12:14 AM
stdout and stderr don't occur sequentially in Eclipse and Netbeans ZelluX Java 15 06-25-2008 12:06 AM
Re: embedding Python and changing stdin, stdout and stderr Vincent Touquet Python 0 09-06-2004 04:35 PM
embedding Python and changing stdin, stdout and stderr Vincent Touquet Python 1 09-03-2004 12:25 PM



Advertisments