Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44563
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'none:': 0.07; 'sys': 0.07; '__name__': 0.09; 'exec': 0.09; 'main()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:/ 10': 0.09; 'subject:process': 0.09; 'wrapper': 0.09; 'python': 0.11; 'def': 0.12; "'__main__':": 0.16; 'cmd': 0.16; 'kern': 0.16; 'main():': 0.16; 'processes.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underlying': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'interpret': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'robert': 0.30; 'info.': 0.31; 'this.': 0.32; 'probably': 0.32; 'run': 0.32; 'open': 0.33; 'url:python': 0.33; 'running': 0.33; 'period': 0.33; 'skip:# 10': 0.33; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'possible': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'so,': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'you.': 0.62; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'account': 0.65; 'world': 0.66; 'believe': 0.68; 'eco': 0.84; 'rita': 0.84; 'snapshot': 0.84; 'terrible': 0.84; 'received:86': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Robert Kern <robert.kern@gmail.com> |
| Subject | Re: python process accounting |
| Date | Tue, 30 Apr 2013 19:19:35 +0100 |
| References | <CAOF-KfhSkQrRPjiyN3bkLwCguFw58Pzf-nu1ne9ZoZDQw3t6SQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | cpc2-cmbg17-2-0-cust347.5-4.cable.virginmedia.com |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| In-Reply-To | <CAOF-KfhSkQrRPjiyN3bkLwCguFw58Pzf-nu1ne9ZoZDQw3t6SQ@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1195.1367345987.3114.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1367345987 news.xs4all.nl 15949 [2001:888:2000:d::a6]:52180 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44563 |
Show key headers only | View raw
On 2013-04-30 17:25, Rita wrote:
> Hi,
>
> I was wondering if it possible to write a python wrapper which will account my
> processes. I would like to account for all the children processes (fork) by
> looking at their /proc/<pid> info. Such as memory, io, open files, stats.
>
> So, instead of me running "/bin/sleep 10", i would like to run it as "pywrap.py
> /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a periodic snapshot
> for whats in /proc/<pid>/stats.
Something like this is approximately the right structure for such a program.
#!/usr/bin/env python
import sys
import subprocess
import time
PERIOD = 1.0 # seconds
def check_stats(pid):
# You will have to implement this.
# Check out psutil:
# https://pypi.python.org/pypi/psutil
print 'Checking process {0}'.format(pid)
def main():
cmd = sys.argv[1:]
p = subprocess.Popen(cmd)
while p.poll() is None:
check_stats(p.pid)
# There are more accurate ways to do this, but this probably
# suffices for you.
time.sleep(PERIOD)
if __name__ == '__main__':
main()
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: python process accounting Robert Kern <robert.kern@gmail.com> - 2013-04-30 19:19 +0100
csiph-web