Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ python:
- "2.7"
- "3.3"
install:
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
Expand All @@ -24,4 +23,6 @@ install:
- source activate test-environment
- python setup.py install
script:
- make test
- make test

sudo: false
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

This is a python module for monitoring memory consumption of a process
as well as line-by-line analysis of memory consumption for python
programs. It is a pure python module and has the `psutil
<http://pypi.python.org/pypi/psutil>`_ module as optional (but highly
recommended) dependencies.
programs. It is a pure python module which depends on the `psutil
<http://pypi.python.org/pypi/psutil>`_ module.


==============
Expand Down Expand Up @@ -385,7 +384,7 @@ file ~/.ipython/ipy_user_conf.py to add the following lines::
between runs.

* Q: Does it work under windows ?
* A: Yes, but you will need the
* A: Yes, thanks to the
`psutil <http://pypi.python.org/pypi/psutil>`_ module.


Expand Down
31 changes: 7 additions & 24 deletions memory_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# .. we'll use this to pass it to the child script ..
_CLEAN_GLOBALS = globals().copy()

__version__ = '0.47'
__version__ = '0.48.dev0'

_CMD_USAGE = "python -m memory_profiler script_file.py"

Expand All @@ -19,6 +19,8 @@
import traceback
from signal import SIGKILL

import psutil


# TODO: provide alternative when multiprocessing is not available
try:
Expand Down Expand Up @@ -48,13 +50,6 @@ def unicode(x, *args):
return str(x)

# .. get available packages ..
try:
import psutil

has_psutil = True
except ImportError:
has_psutil = False

try:
import tracemalloc

Expand Down Expand Up @@ -92,12 +87,6 @@ def _get_child_memory(process, meminfo_attr=None):
"""
Returns a generator that yields memory for all child processes.
"""
if not has_psutil:
raise NotImplementedError((
"The psutil module is required to monitor the "
"memory usage of child processes."
))

# Convert a pid to a process
if isinstance(process, int):
if process == -1: process = os.getpid()
Expand Down Expand Up @@ -344,10 +333,9 @@ def memory_usage(proc=-1, interval=.1, timeout=None, timestamps=False,
if retval:
ret = ret, returned
except Exception:
if has_psutil:
parent = psutil.Process(os.getpid())
for child in parent.children(recursive=True):
os.kill(child.pid, SIGKILL)
parent = psutil.Process(os.getpid())
for child in parent.children(recursive=True):
os.kill(child.pid, SIGKILL)
p.join(0)
raise

Expand Down Expand Up @@ -1086,10 +1074,9 @@ def choose_backend(new_backend=None):

_backend = 'no_backend'
all_backends = [
('psutil', has_psutil),
('psutil', True),
('posix', os.name == 'posix'),
('tracemalloc', has_tracemalloc),
('no_backend', True)
]
backends_indices = dict((b[0], i) for i, b in enumerate(all_backends))

Expand All @@ -1100,10 +1087,6 @@ def choose_backend(new_backend=None):
if is_available:
_backend = n_backend
break
if _backend == 'no_backend':
raise NotImplementedError(
'Tracemalloc or psutil module is required for non-unix '
'platforms')
if _backend != new_backend and new_backend is not None:
warnings.warn('{0} can not be used, {1} used instead'.format(
new_backend, _backend))
Expand Down
29 changes: 24 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import memory_profiler
from distutils.core import setup
import setuptools
import os
import io
import re
from setuptools import setup


# https://packaging.python.org/guides/single-sourcing-package-version/
def read(*names, **kwargs):
with io.open(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")
) as fp:
return fp.read()


def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)


CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Expand All @@ -24,13 +43,13 @@
name='memory_profiler',
description='A module for monitoring memory usage of a python program',
long_description=open('README.rst').read(),
version=memory_profiler.__version__,
version=find_version("memory_profiler.py"),
author='Fabian Pedregosa',
author_email='f@bianp.net',
url='http://pypi.python.org/pypi/memory_profiler',
py_modules=['memory_profiler'],
scripts=['mprof'],
install_requires=['psutil'],
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
license='BSD'

)