Skip to content

Commit a07c138

Browse files
committed
ENH: Add sync option to savepkl, sync when saving result file
1 parent d5d22be commit a07c138

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

nipype/pipeline/engine/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,17 @@ def save_resultfile(result, cwd, name, rebase=None):
236236

237237
if result.outputs is None:
238238
logger.warning('Storing result file without outputs')
239-
savepkl(resultsfile, result)
239+
savepkl(resultsfile, result, sync=True)
240240
return
241241
try:
242242
output_names = result.outputs.copyable_trait_names()
243243
except AttributeError:
244244
logger.debug('Storing non-traited results, skipping rebase of paths')
245-
savepkl(resultsfile, result)
245+
savepkl(resultsfile, result, sync=True)
246246
return
247247

248248
if not rebase:
249-
savepkl(resultsfile, result)
249+
savepkl(resultsfile, result, sync=True)
250250
return
251251

252252
backup_traits = {}
@@ -262,7 +262,7 @@ def save_resultfile(result, cwd, name, rebase=None):
262262
backup_traits[key] = old
263263
val = rebase_path_traits(result.outputs.trait(key), old, cwd)
264264
setattr(result.outputs, key, val)
265-
savepkl(resultsfile, result)
265+
savepkl(resultsfile, result, sync=True)
266266
finally:
267267
# Restore resolved paths from the outputs dict no matter what
268268
for key, val in list(backup_traits.items()):

nipype/utils/filemanip.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -789,19 +789,18 @@ def read_stream(stream, logger=None, encoding=None):
789789
return out.splitlines()
790790

791791

792-
def savepkl(filename, record, versioning=False):
793-
with SoftFileLock('%s.lock' % filename):
794-
with open(filename, 'wb') as fobj:
795-
pkl_file = gzip.GzipFile(fileobj=fobj) if filename.endswith('.pklz') else fobj
796-
if versioning:
797-
from nipype import __version__ as version
798-
metadata = json.dumps({'version': version})
799-
800-
pkl_file.write(metadata.encode('utf-8'))
801-
pkl_file.write('\n'.encode('utf-8'))
802-
803-
pickle.dump(record, pkl_file)
804-
# Pickle files need to be available immediately, so force a sync
792+
def savepkl(filename, record, versioning=False, sync=False):
793+
with open(filename, 'wb') as fobj:
794+
pkl_file = gzip.GzipFile(fileobj=fobj) if filename.endswith('.pklz') else fobj
795+
if versioning:
796+
from nipype import __version__ as version
797+
metadata = json.dumps({'version': version})
798+
799+
pkl_file.write(metadata.encode('utf-8'))
800+
pkl_file.write('\n'.encode('utf-8'))
801+
802+
pickle.dump(record, pkl_file)
803+
if sync:
805804
fobj.flush()
806805
os.fsync(fobj.fileno())
807806

0 commit comments

Comments
 (0)