Skip to content

Commit

Permalink
Merge pull request #18 from astrofrog/fix-compat-psutil
Browse files Browse the repository at this point in the history
Fix compatibility with latest psutil while maintaining compatibility with older versions
  • Loading branch information
astrofrog committed Feb 3, 2016
2 parents 40ea60c + b8dcf28 commit c544525
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
48 changes: 20 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
language: python

python:
- 2.6
- 2.7
- 3.3
- 3.4
language: c

os:
- linux
- osx

env:
matrix:
- PYTHON_VERSION=2.7
- PYTHON_VERSION=3.3
- PYTHON_VERSION=3.4
- PYTHON_VERSION=3.5
global:
- CONDA_DEPENDENCIES='numpy matplotlib psutil'
- PIP_DEPENDENCIES='coveralls pytest-cov'
- SETUP_XVFB=True

before_install:

# Install conda
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes conda

# Create environment
- conda create --yes -n test python=$TRAVIS_PYTHON_VERSION
- source activate test

# Make sure that interactive matplotlib backends work
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

install:
- conda install --yes pip pytest numpy matplotlib psutil
- pip install coveralls pytest-cov
- git clone git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh

script:
- py.test --cov psrecord
- py.test --cov psrecord psrecord

after_success:
- coveralls
- coveralls
18 changes: 16 additions & 2 deletions psrecord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
import argparse


def get_percent(process):
try:
return process.cpu_percent()
except AttributeError:
return process.get_cpu_percent()


def get_memory(process):
try:
return process.memory_info()
except AttributeError:
return process.get_memory_info()


def all_children(pr):
processes = []
try:
Expand Down Expand Up @@ -142,8 +156,8 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,

# Get current CPU and memory
try:
current_cpu = pr.get_cpu_percent()
current_mem = pr.get_memory_info()
current_cpu = get_percent(pr)
current_mem = get_memory(pr)
except:
break
current_mem_real = current_mem.rss / 1024. ** 2
Expand Down

0 comments on commit c544525

Please sign in to comment.