|
22 | 22 | import nibabel as nb |
23 | 23 |
|
24 | 24 | from .base import (traits, TraitedSpec, DynamicTraitedSpec, File, |
25 | | - Undefined, isdefined, OutputMultiPath, |
| 25 | + Undefined, isdefined, OutputMultiPath, runtime_profile, |
26 | 26 | InputMultiPath, BaseInterface, BaseInterfaceInputSpec) |
27 | 27 | from .io import IOBase, add_traits |
28 | 28 | from ..external.six import string_types |
29 | 29 | from ..testing import assert_equal |
30 | 30 | from ..utils.filemanip import (filename_to_list, copyfile, split_filename) |
31 | 31 | from ..utils.misc import getsource, create_function_from_source |
32 | 32 |
|
| 33 | +if runtime_profile: |
| 34 | + try: |
| 35 | + import psutil |
| 36 | + except ImportError as exc: |
| 37 | + logger.info('Unable to import packages needed for runtime profiling. '\ |
| 38 | + 'Turning off runtime profiler. Reason: %s' % exc) |
| 39 | + runtime_profile = False |
33 | 40 |
|
34 | 41 | class IdentityInterface(IOBase): |
35 | 42 | """Basic interface class generates identity mappings |
@@ -459,20 +466,10 @@ def _function_handle_wrapper(queue, **kwargs): |
459 | 466 | if isdefined(value): |
460 | 467 | args[name] = value |
461 | 468 |
|
462 | | - # Runtime profiler on if dependecies available |
463 | | - try: |
464 | | - import psutil |
465 | | - from nipype.interfaces.base import get_max_resources_used |
466 | | - import multiprocessing |
467 | | - runtime_profile = True |
468 | | - except ImportError as exc: |
469 | | - logger.info('Unable to import packages needed for runtime profiling. '\ |
470 | | - 'Turning off runtime profiler. Reason: %s' % exc) |
471 | | - runtime_profile = False |
472 | | - |
473 | 469 | # Profile resources if set |
474 | | - #runtime_profile=False |
475 | 470 | if runtime_profile: |
| 471 | + from nipype.interfaces.base import get_max_resources_used |
| 472 | + import multiprocessing |
476 | 473 | # Init communication queue and proc objs |
477 | 474 | queue = multiprocessing.Queue() |
478 | 475 | proc = multiprocessing.Process(target=_function_handle_wrapper, |
|
0 commit comments