Skip to content

fix: remove psutils usage by default #1561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2016
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
6 changes: 3 additions & 3 deletions nipype/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# full release. '.dev' as a _version_extra string means this is a development
# version
_version_major = 0
_version_minor = 13
_version_micro = 0
_version_extra = '-dev' # Remove -dev for release
_version_minor = 12
_version_micro = 1
_version_extra = '' # Remove -dev for release


def get_nipype_gitversion():
Expand Down
18 changes: 9 additions & 9 deletions nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@
from .. import __version__
from ..external.six import string_types, text_type

runtime_profile = str2bool(config.get('execution', 'profile_runtime'))

nipype_version = LooseVersion(__version__)

iflogger = logging.getLogger('interface')

if runtime_profile:
try:
import psutil
except ImportError as exc:
iflogger.info('Unable to import packages needed for runtime profiling. '\
'Turning off runtime profiler. Reason: %s' % exc)
runtime_profile = False

__docformat__ = 'restructuredtext'

Expand Down Expand Up @@ -1350,15 +1359,6 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
# Init logger
logger = logging.getLogger('workflow')

# Default to profiling the runtime
try:
import psutil
runtime_profile = True
except ImportError as exc:
logger.info('Unable to import packages needed for runtime profiling. '\
'Turning off runtime profiler. Reason: %s' % exc)
runtime_profile = False

# Init variables
PIPE = subprocess.PIPE
cmdline = runtime.cmdline
Expand Down
29 changes: 17 additions & 12 deletions nipype/interfaces/tests/test_runtime_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

# Import packages
import unittest
from nipype.interfaces.base import traits, CommandLine, CommandLineInputSpec

try:
import psutil
run_profiler = True
skip_profile_msg = 'Run profiler tests'
except ImportError as exc:
skip_profile_msg = 'Missing python packages for runtime profiling, skipping...\n'\
'Error: %s' % exc
run_profiler = False
from nipype.interfaces.base import (traits, CommandLine, CommandLineInputSpec,
runtime_profile)

run_profile = runtime_profile

if run_profile:
try:
import psutil
skip_profile_msg = 'Run profiler tests'
except ImportError as exc:
skip_profile_msg = 'Missing python packages for runtime profiling, skipping...\n'\
'Error: %s' % exc
run_profile = False
else:
skip_profile_msg = 'Not running profiler'

# UseResources inputspec
class UseResourcesInputSpec(CommandLineInputSpec):
Expand Down Expand Up @@ -355,7 +360,7 @@ def _run_function_workflow(self, num_gb, num_threads):
return start_str, finish_str

# Test resources were used as expected in cmdline interface
@unittest.skipIf(run_profiler == False, skip_profile_msg)
@unittest.skipIf(run_profile == False, skip_profile_msg)
def test_cmdline_profiling(self):
'''
Test runtime profiler correctly records workflow RAM/CPUs consumption
Expand Down Expand Up @@ -397,7 +402,7 @@ def test_cmdline_profiling(self):
msg=threads_err)

# Test resources were used as expected
@unittest.skipIf(run_profiler == False, skip_profile_msg)
@unittest.skipIf(run_profile == False, skip_profile_msg)
def test_function_profiling(self):
'''
Test runtime profiler correctly records workflow RAM/CPUs consumption
Expand Down
23 changes: 10 additions & 13 deletions nipype/interfaces/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
import nibabel as nb

from .base import (traits, TraitedSpec, DynamicTraitedSpec, File,
Undefined, isdefined, OutputMultiPath,
Undefined, isdefined, OutputMultiPath, runtime_profile,
InputMultiPath, BaseInterface, BaseInterfaceInputSpec)
from .io import IOBase, add_traits
from ..external.six import string_types
from ..testing import assert_equal
from ..utils.filemanip import (filename_to_list, copyfile, split_filename)
from ..utils.misc import getsource, create_function_from_source

if runtime_profile:
try:
import psutil
except ImportError as exc:
logger.info('Unable to import packages needed for runtime profiling. '\
'Turning off runtime profiler. Reason: %s' % exc)
runtime_profile = False

class IdentityInterface(IOBase):
"""Basic interface class generates identity mappings
Expand Down Expand Up @@ -459,20 +466,10 @@ def _function_handle_wrapper(queue, **kwargs):
if isdefined(value):
args[name] = value

# Runtime profiler on if dependecies available
try:
import psutil
from nipype.interfaces.base import get_max_resources_used
import multiprocessing
runtime_profile = True
except ImportError as exc:
logger.info('Unable to import packages needed for runtime profiling. '\
'Turning off runtime profiler. Reason: %s' % exc)
runtime_profile = False

# Profile resources if set
#runtime_profile=False
if runtime_profile:
from nipype.interfaces.base import get_max_resources_used
import multiprocessing
# Init communication queue and proc objs
queue = multiprocessing.Queue()
proc = multiprocessing.Process(target=_function_handle_wrapper,
Expand Down
1 change: 1 addition & 0 deletions nipype/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
parameterize_dirs = true
poll_sleep_duration = 60
xvfb_max_wait = 10
profile_runtime = false

[check]
interval = 1209600
Expand Down