-
Notifications
You must be signed in to change notification settings - Fork 532
[ENH] Revising use of subprocess.Popen #2289
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
Conversation
Make sure everything is tidied up after using Popen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is ready for comment, but a couple comments anyway. Assume the commented-out bits will be uncommented or deleted before merge?
nipype/interfaces/base.py
Outdated
stderr=sp.PIPE, | ||
) | ||
o, e = proc.communicate() | ||
return o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an API change. Even if not used internally, someone may depend on this method. Does nipype have a process for deprecating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should start using https://pypi.python.org/pypi/deprecation ?
nipype/interfaces/base.py
Outdated
|
||
runtime.returncode = proc.returncode | ||
proc.terminate() # Ensure we are done | ||
gc.collect() # Force GC for a cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal here is just to clean up proc
internals, not stdout
/stderr
, etc?
nipype/interfaces/base.py
Outdated
proc = sp.Popen( | ||
cmd(name), stdout=sp.PIPE, stderr=sp.PIPE, shell=True, | ||
env=environ, close_fds=True) | ||
o, e = proc.communicate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd replace e
with _
, since it's unused.
@@ -1452,12 +1448,28 @@ def _process(drain=0): | |||
result['merged'] = result['stdout'] | |||
result['stdout'] = [] | |||
else: | |||
proc.communicate() # Discard stdout and stderr | |||
stdout, stderr = proc.communicate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make these stdoutstr
, stdinstr
, to be consistent with if output.startswith('file')
, so that the same del
statement will work in all cases.
Alternately, it might be simplest to just run gc.collect()
in CommandLine._run_interface
, after this function is called and everything is allowed to go out of scope.
nipype/interfaces/base.py
Outdated
result['stdout'] = read_stream(stdoutstr, logger=iflogger) | ||
result['stderr'] = read_stream(stderrstr, logger=iflogger) | ||
del stdoutstr | ||
del stderrstr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, meant for these to replace the del stdout
and del stderr
below, since stdoutstr
and stderrstr
can be created in the other branch.
I guess, though, that those only exist under certain sub-branches. Not sure how you want to go about this.
nipype/interfaces/base.py
Outdated
_ = getattr(dup, key) | ||
except: | ||
pass | ||
# for key in self.copyable_trait_names(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dynamic traits won't work without these. i'm not sure we have a test for it but this is the relevant issue and PR.
nipype/interfaces/base.py
Outdated
@@ -1620,6 +1642,8 @@ def _get_environ(self): | |||
return getattr(self.inputs, 'environ', {}) | |||
|
|||
def version_from_command(self, flag='-v'): | |||
iflogger.warning('version_from_command member of CommandLine was ' | |||
'Deprecated in nipype-1.0.0 and deleted in 2.0.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should perhaps keep this in the 1.0 branch so deleted in 1.1
This PR:
Popen
inCommandLineInterface
ensuring they are terminated and garbage-collected.interfaces.base
)interfaces.base
)interfaces.base
)engine.workflows
andplugins.multiproc
.get_dependencies
and executes it only iff the optionexecution. get_linked_libs
isTrue
(which is the default value).