Skip to content

FIX: TypeError bug for PBS process communication in python3 #1987

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 1 commit into from
May 3, 2017

Conversation

gjcooper
Copy link
Contributor

@gjcooper gjcooper commented May 1, 2017

When using python3 to call the PBS status command line script there is a TypeError crash (bytes-like object not str required). To fix this I have used the interfaces.base CommandLine class.

CommandLine already uses the default encoding to decode the
stdout/stderr of the command, so take advantage of that functionality
rather than re-implementing.

First try was to implement decoding pattern seen elsewhere - then I
changed my mind and used a CommandLine object from the interfaces.base
module. (It was already imported to the module anyway)

First Attempt

Decode the stderr using the default encoding

Second Attempt

Use the nipype CommandLine class instead of Popen

Remove unused modules

Ignore exceptions in qstat CommandLine call.

CommandLine already uses the default encoding to decode the
stdout/stderr of the command, so take advantage of that functionality
rather than re-implementing.

First try was to implement decoding pattern seen elsewhere - then I
changed my mind and used a CommandLine object from the interfaces.base
module.

First Attempt
-------------

Decode the stderr using the default encoding

* Fixes TypeError bug for PBS jobs running on python3.x
* Fixes issue nipy#1959

Second Attempt
--------------

Use the nipype CommandLine class instead of Popen

Remove unused modules

Ignore exceptions in qstat CommandLine call.
@codecov-io
Copy link

codecov-io commented May 1, 2017

Codecov Report

Merging #1987 into master will increase coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1987      +/-   ##
==========================================
+ Coverage   72.29%   72.29%   +<.01%     
==========================================
  Files        1089     1089              
  Lines       55586    55584       -2     
  Branches     8010     8010              
==========================================
- Hits        40184    40183       -1     
+ Misses      14148    14147       -1     
  Partials     1254     1254
Flag Coverage Δ
#smoketests 72.29% <0%> (ø) ⬆️
#unittests 69.81% <0%> (ø) ⬆️
Impacted Files Coverage Δ
nipype/pipeline/plugins/pbs.py 18.18% <0%> (-0.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae7af2d...e5daf5d. Read the comment docs.

@gjcooper
Copy link
Contributor Author

gjcooper commented May 2, 2017

Additionally,

I have noticed other places in the codebase that perhaps would suffer from the same bug. I could attempt fixes for these Popen calls (via a similar method) however I wouldn't have the capability to test the other batch submission systems.

In particular I have noticed there there are possible similar problems in:

  • _is_pending in the oar plugin module
  • _qacct_verified_complete and _run_qstat in the sge plugin module

There are some other places, but I would be less confident adjusting those to use CommandLine.

Copy link
Contributor

@oesteban oesteban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, feel free to open new PRs, so that we keep their objective clear.

Please, add an entry in the CHANGES file for this PR.

_, e = proc.communicate()
result = CommandLine('qstat {}'.format(taskid),
environ=dict(os.environ),
terminal_output='allatonce',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure 'allatonce' generates both stdout and stderr in the runtime object. Have you checked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allatonce doesn't stream but still separates stdout and stderr

stderr=subprocess.PIPE)
_, e = proc.communicate()
result = CommandLine('qstat {}'.format(taskid),
environ=dict(os.environ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this line if you want to use the default environment

@satra
Copy link
Member

satra commented May 3, 2017

@gjcooper - i'll merge this, but it would be good to clean up the other places where you spot this.

@satra satra merged commit a092cde into nipy:master May 3, 2017
@mgxd mgxd mentioned this pull request May 3, 2017
@gjcooper gjcooper deleted the PBS_Type_fix branch May 4, 2017 00:28
@gjcooper gjcooper restored the PBS_Type_fix branch May 25, 2017 04:28
@gjcooper gjcooper deleted the PBS_Type_fix branch May 25, 2017 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants