Skip to content

Commit 777fa20

Browse files
committed
fix: force encoding when None
1 parent 3ace38d commit 777fa20

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

nipype/interfaces/base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,9 @@ def __init__(self, name, impl):
11501150
self._buf = ''
11511151
self._rows = []
11521152
self._lastidx = 0
1153+
self.default_encoding = locale.getdefaultlocale()[1]
1154+
if self.default_encoding is None:
1155+
self.default_encoding = 'UTF-8'
11531156

11541157
def fileno(self):
11551158
"Pass-through for file descriptor."
@@ -1161,10 +1164,10 @@ def read(self, drain=0):
11611164
if not drain:
11621165
break
11631166

1164-
def _read(self, drain):
1167+
def _read(self, drain, encoding):
11651168
"Read from the file descriptor"
11661169
fd = self.fileno()
1167-
buf = os.read(fd, 4096).decode(locale.getdefaultlocale()[1])
1170+
buf = os.read(fd, 4096).decode(self.default_encoding)
11681171
if not buf and not self._buf:
11691172
return None
11701173
if '\n' not in buf:
@@ -1203,6 +1206,9 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
12031206
raise RuntimeError('Xvfb was not found, X redirection aborted')
12041207
cmdline = 'xvfb-run -a ' + cmdline
12051208

1209+
default_encoding = locale.getdefaultlocale()[1]
1210+
if default_encoding is None:
1211+
default_encoding = 'UTF-8'
12061212
if output == 'file':
12071213
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
12081214
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
@@ -1257,17 +1263,17 @@ def _process(drain=0):
12571263
result['merged'] = [r[1] for r in temp]
12581264
if output == 'allatonce':
12591265
stdout, stderr = proc.communicate()
1260-
stdout = stdout.decode(locale.getdefaultlocale()[1])
1261-
stderr = stderr.decode(locale.getdefaultlocale()[1])
1266+
stdout = stdout.decode(default_encoding)
1267+
stderr = stderr.decode(default_encoding)
12621268
result['stdout'] = stdout.split('\n')
12631269
result['stderr'] = stderr.split('\n')
12641270
result['merged'] = ''
12651271
if output == 'file':
12661272
ret_code = proc.wait()
12671273
stderr.flush()
12681274
stdout.flush()
1269-
result['stdout'] = [line.decode(locale.getdefaultlocale()[1]).strip() for line in open(outfile, 'rb').readlines()]
1270-
result['stderr'] = [line.decode(locale.getdefaultlocale()[1]).strip() for line in open(errfile, 'rb').readlines()]
1275+
result['stdout'] = [line.decode(default_encoding).strip() for line in open(outfile, 'rb').readlines()]
1276+
result['stderr'] = [line.decode(default_encoding).strip() for line in open(errfile, 'rb').readlines()]
12711277
result['merged'] = ''
12721278
if output == 'none':
12731279
proc.communicate()

nipype/pipeline/plugins/pbs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ def _submit_batchtask(self, scriptfile, node):
8787
iflogger.setLevel(logging.getLevelName('CRITICAL'))
8888
tries = 0
8989
while True:
90-
result = cmd.run()
91-
'''
9290
try:
9391
result = cmd.run()
9492
except Exception as e:
@@ -102,7 +100,6 @@ def _submit_batchtask(self, scriptfile, node):
102100
text_type(e))))
103101
else:
104102
break
105-
'''
106103
iflogger.setLevel(oldlevel)
107104
# retrieve pbs taskid
108105
taskid = result.runtime.stdout.split('.')[0]

0 commit comments

Comments
 (0)