Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5917

Re: how to get PID from subprocess library

From TheSaint <nobody@nowhere.net.no>
Newsgroups comp.lang.python
Subject Re: how to get PID from subprocess library
Followup-To comp.lang.python
Date 2011-05-21 20:50 +0800
Organization Aioe.org NNTP Server
Message-ID <ir8cfj$2s4$1@speranza.aioe.org> (permalink)
References <ir3eu1$kgq$1@speranza.aioe.org> <mailman.1872.1305955023.9059.python-list@python.org>

Followups directed to: comp.lang.python

Show all headers | View raw


Kushal Kumaran wrote:

> That's how it is able to give you the status.  So, if you
> are using getstatusoutput, you will have only one instance of your
> command running.

My intent is to launch only one program instance, which will goes as daemon.
To avoid a second call I'd like rather to use Python than 
==============================code=========================================
    def start(self):
        '''try to start aria2c as a daemon and return its handle to where it 
can
        proceed to issue commands'''

        # aria2c is running, then don't try it again
        if (chkout('ps -A |grep aria2c')[0] > 0):
            try:
                chkout(self.ARIA_CMD)
            except:
                raise SystemExit('aria2c is not working as deamon')
        elif self.handle: return self.handle
        # everything is good, it will return an handle
        self.handle= \
        xmlrpclib.ServerProxy('http://localhost:%s/rpc' %int(self.numport))
        return self.handle
==============================code=========================================

Here I've named subprocess.getstatusoutput as chkout, I'm calling 2 more 
programs to find whether there's a running instance of aria2c. I think it's 
not nice, python libraries should get the matter done.

-- 
goto /dev/null

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to get PID from subprocess library TheSaint <nobody@nowhere.net.no> - 2011-05-20 00:02 +0800
  Re: how to get PID from subprocess library Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-05-21 10:46 +0530
    Re: how to get PID from subprocess library TheSaint <nobody@nowhere.net.no> - 2011-05-21 20:50 +0800
      Re: how to get PID from subprocess library Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-05-22 15:34 +0530
        Re: how to get PID from subprocess library TheSaint <nobody@nowhere.net.no> - 2011-05-22 21:41 +0800
          Re: how to get PID from subprocess library GMail Felipe <felipe.vinturini@gmail.com> - 2011-05-22 12:45 -0300
            Re: how to get PID from subprocess library TheSaint <nobody@nowhere.net.no> - 2011-05-23 19:06 +0800
      Re: how to get PID from subprocess library Anssi Saari <as@sci.fi> - 2011-05-24 13:45 +0300
        Re: how to get PID from subprocess library TheSaint <nobody@nowhere.net.no> - 2011-05-24 21:36 +0800

csiph-web