Matthias,

  It's up to you.  Submit the patch you like best.  I am all for the simplest 
approach.

Brad

>>> On 1/23/2008 at 1:28 PM, in message
<[EMAIL PROTECTED]>, Matthias
Blankenhaus <[EMAIL PROTECTED]> wrote:

> 
> On Wed, 23 Jan 2008, Matt Massie wrote:
> 
>> you can also run all threads as daemonized threads (or "detached" in
>> POSIX).  daemon threads exit immediately and do not expect another thread to
>> wait on their exit value.
>> 
>> thread.setDeamon(1)
>> thread.start()
> 
> I have tried this out and it worked as well.  Thanx, Matt :)
> 
> I have no preference either way,
> 
> Matthias
> 
>> 
>> http://docs.python.org/lib/thread-objects.html 
>> 
>> it'll allow you to Ctrl+C any python threaded program because the thread
>> will immediately exit withouth waiting on the main thread to join it.
>> 
>> of course, this can't work if you want to know the exit value of a thread.
>> 
>> -matt
>> 
>> 
>> 
>> On 1/23/08, Matthias Blankenhaus <[EMAIL PROTECTED]> wrote:
>> >
>> >
>> >
>> > On Wed, 23 Jan 2008, Brad Nicholes wrote:
>> >
>> > >    I am running into another problem since the switch to popen2 in
>> > tcpconn.py.  After running for several days, the tcpconn.py module died
>> > due to too many open files.  The traceback points back to the popen2
>> > call.  Does anybody know what needs to be cleaned up?  I saw some examples
>> > of having to close stdin.  Do we need to close stdin, stdout and stderr?  
> or
>> > is there something else that is missing.
>> >
>> > Here is a patch that fixes the open fds and also allows you now to ctrl-c
>> > the code:
>> >
>> > diff -u tcpconn.py tcpconn.py.new
>> > --- tcpconn.py  2008-01-23 11:43:05.000000000 -0800
>> > +++ tcpconn.py.new      2008-01-23 11:44:30.000000000 -0800
>> > @@ -32,6 +32,7 @@
>> >
>> > import os, sys, popen2
>> > import threading
>> > +import select
>> > import time
>> >
>> > _WorkerThread = None    #Worker thread object
>> > @@ -174,14 +175,22 @@
>> >      '''This thread contunually gathers the current states of the tcp
>> > socket
>> >      connections on the machine.  The refresh rate is controlled by the
>> >      RefreshRate parameter that is passed in through th gmond.conf
>> > file.'''
>> > -
>> > +
>> >      def __init__(self):
>> >          threading.Thread.__init__(self)
>> >          self.running = False
>> >          self.shuttingdown = False
>> > +        self.popenChild = None
>> >
>> >      def shutdown(self):
>> >          self.shuttingdown = True
>> > +        if self.popenChild != None:
>> > +            try:
>> > +                self.popenChild.wait()
>> > +            except OSError, e:
>> > +                if e.errno == 10: # No child processes
>> > +                    pass
>> > +
>> >          if not self.running:
>> >              return
>> >          self.join()
>> > @@ -210,9 +219,17 @@
>> >                  tempconns[conn] = 0
>> >
>> >              #Call the netstat utility and split the output into separate
>> > lines
>> > -            netstat_output=popen2.popen2(["netstat", '-t', '-a'],
>> > mode='r')[0].read()
>> > -            lines = netstat_output.splitlines()
>> > -            os.wait()
>> > +            fd_poll = select.poll()
>> > +            self.popenChild = popen2.Popen3("netstat -t -a")
>> > +            fd_poll.register(self.popenChild.fromchild)
>> > +
>> > +            poll_events = fd_poll.poll()
>> > +
>> > +            if (len(poll_events) == 0):             # Timeout
>> > +                continue
>> > +
>> > +            for (fd, events) in poll_events:
>> > +                lines = self.popenChild.fromchild.readlines()
>> >
>> >              #Iterate through the netstat output looking for the 'tcp'
>> > keyword in the tcp_at
>> >              # position and the state information in the tcp_state_at
>> > position. Count each
>> > @@ -284,11 +301,16 @@
>> >
>> > #This code is for debugging and unit testing
>> > if __name__ == '__main__':
>> > -    params = {'Refresh': '20'}
>> > -    metric_init(params)
>> > -    while True:
>> > -        for d in _descriptors:
>> > -            v = d['call_back'](d['name'])
>> > -            print 'value for %s is %u' % (d['name'],  v)
>> > -        time.sleep(5)
>> > +    try:
>> > +        params = {'Refresh': '20'}
>> > +        metric_init(params)
>> > +        while True:
>> > +            for d in _descriptors:
>> > +                v = d['call_back'](d['name'])
>> > +                print 'value for %s is %u' % (d['name'],  v)
>> > +            time.sleep(5)
>> > +    except KeyboardInterrupt:
>> > +        time.sleep(0.2)
>> > +        os._exit(1)
>> > +
>> >
>> >
>> > >
>> > > Brad
>> > >
>> > >
>> > >
>> > -------------------------------------------------------------------------
>> > > This SF.net email is sponsored by: Microsoft
>> > > Defy all challenges. Microsoft(R) Visual Studio 2008.
>> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ 
>> > > _______________________________________________
>> > > Ganglia-developers mailing list
>> > > [email protected] 
>> > > https://lists.sourceforge.net/lists/listinfo/ganglia-developers 
>> > >
>> >
>> > -------------------------------------------------------------------------
>> > This SF.net email is sponsored by: Microsoft
>> > Defy all challenges. Microsoft(R) Visual Studio 2008.
>> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ 
>> > _______________________________________________
>> > Ganglia-developers mailing list
>> > [email protected] 
>> > https://lists.sourceforge.net/lists/listinfo/ganglia-developers 
>> >
>> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ 
> _______________________________________________
> Ganglia-developers mailing list
> [email protected] 
> https://lists.sourceforge.net/lists/listinfo/ganglia-developers 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to