Skip to content

fix: unicode characters in stderr on certain systems #1394

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 7 commits into from
Mar 5, 2016

Conversation

satra
Copy link
Member

@satra satra commented Mar 4, 2016

@satra satra mentioned this pull request Mar 4, 2016
@@ -655,17 +655,17 @@ def test_CommandLine_output():
ci = nib.CommandLine(command='ls -l')
ci.inputs.terminal_output = 'allatonce'
res = ci.run()
yield assert_equal, res.runtime.merged, ''
yield assert_equal, text_type(res.runtime.merged), text_type('')
Copy link
Member

Choose a reason for hiding this comment

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

This should work fine without text_type. On Python 2:

In [78]: unicode('hi there') == 'hi there'
Out[78]: True

On Python 3, literal strings are unicode, so you're comparing unicode to unicode already.

@satra
Copy link
Member Author

satra commented Mar 4, 2016

thank you @matthew-brett - i think i have cleaned this up for this issue.

satra added a commit that referenced this pull request Mar 5, 2016
fix: unicode characters in stderr on certain systems
@satra satra merged commit cb207f8 into nipy:master Mar 5, 2016
@PeerHerholz
Copy link

Hi,

I stumbled across a weird error (at least for me) when running my nipype script and I think
it might be related to the error discussed here.

Here's the error message:

Exception in thread Thread-7:
Traceback (most recent call last):
File "/Users/peerherholz/anaconda/envs/py27/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/Users/peerherholz/anaconda/envs/py27/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/peerherholz/anaconda/envs/py27/lib/python2.7/multiprocessing/pool.py", line 389, in _handle_results
task = get()
TypeError: ('function takes exactly 5 arguments (7 given)', <type 'exceptions.UnicodeDecodeError'>, ('utf8', 'MATLAB code threw an exception:\nNo executable modules, but still unresolved dependencies or incomplete module inputs.\nFile:/Applications/spm12/spm_jobman.m\nName:/Applications/spm12/spm_jobman.m\nLine:47\nFile:Path\to\my\file\realign\pyscript_realign.m\nName:fill_run_job\nLine:115\nFile:pm_jobman\nName:pyscript_realign\nLine:461\nFile:\xf7\nName:\x1a\nLine:', 455, 456, 'invalid start byte', '\nInterface MatlabCommand failed to run.', '\nInterface Realign failed to run.'))

It only appears when I merge the 3D .nii files into a 4D file using Fsl Merge before realignment. Using 3D files as input for the realignment node works fine.

@satra: I checked if the fixes you made are included in my version and they are. I also updated nipype and it's dependencies. Unfortunately, it didn't resolve the error.

I'm using python 2.7..12 in OS X El Capitan, both, in a VM and on my macbook.
In either case, the error appears.

Can you think of anything that I could try to fix that?

@satra
Copy link
Member Author

satra commented Feb 4, 2017

@PeerHerholz - there are two pieces to this error:

  1. the utf output from matlab when it errors that should be parsed and decoded properly
  2. the issue with realign itself. are you by any chance giving spm a compressed nifti file? can you ensure the outputtype of fslmerge is NIFTI and not NIFIT_GZ

@PeerHerholz
Copy link

@satra thank you very much for your fast response and the pointers.

I indeed forgot to set the output type in my merge node. After setting it to NIFTI the realignment and coregister nodes work fine (I'm basically trying to run the "classic" SPM pipeline, including unified segmentation). However, now the same error appears either in the segmentation or normalize _structural node (weirdly, depending on the machine I us).
As far as I can tell and based on the detailed pipeline graph, the flow of files fits.

I thought it might be related to the default encoding, as I'm using Anaconda and Spyder, but no matter how I call the script (e.g. within spyder, command prompt, etc.) the error remains the same.

Sorry, if this is a very noobish thing to guess / ask.

@satra
Copy link
Member Author

satra commented Feb 15, 2017

@PeerHerholz - let me take a look

@PeerHerholz
Copy link

@satra thank you very much.

After some additional tests, I can provide you with some (hopefully) helpful information:

After I changed the my pipeline from multiproc to serial the node seem to work, but only for one
run. After that the following error appears:

170214-20:09:40,751 workflow INFO:
Traceback (most recent call last):
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/pipeline/plugins/linear.py", line 43, in run
node.run(updatehash=updatehash)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/pipeline/engine/nodes.py", line 366, in run
self._run_interface()
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/pipeline/engine/nodes.py", line 476, in _run_interface
self._result = self._run_command(execute)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/pipeline/engine/nodes.py", line 607, in _run_command
result = self._interface.run()
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1085, in run
runtime = self._run_wrapper(runtime)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1033, in _run_wrapper
runtime = self._run_interface(runtime)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/spm/base.py", line 323, in _run_interface
results = self.mlab.run()
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1085, in run
runtime = self._run_wrapper(runtime)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1728, in _run_wrapper
runtime = self._run_interface(runtime)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/matlab.py", line 144, in _run_interface
runtime = super(MatlabCommand, self)._run_interface(runtime)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1759, in _run_interface
redirect_x=self._redirect_x)
File "/Users/peerherholz/Downloads/nipype-0.13.0-rc1/nipype/interfaces/base.py", line 1514, in run_command
stderr = stderr.decode(default_encoding)
File "/Users/peerherholz/anaconda/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf7 in position 440: invalid start byte

After I upgraded nipype to the developer version, the same thing happened.
Also changing the apparently crucial line in base.py from
stderr = stderr.decode(default_encoding) to
stderr = stderr.decode(locale.getdefaultlocale()[1]) as in #1394
had no effect. The same error indicating the same lines of code appears.

I'm truly sorry for the hustle.

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.

python 2 bytes/str issue
3 participants