Skip to content

Commit

Permalink
DOC save.pickle(): better error message for error due to large array
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Feb 8, 2017
1 parent 5a5ad43 commit 0b67a6e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions eelbrain/_io/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ def pickle(obj, dest=None, protocol=HIGHEST_PROTOCOL):
if not os.path.splitext(dest)[1]:
dest += '.pickled'

with open(dest, 'wb') as fid:
dump(obj, fid, protocol)
try:
with open(dest, 'wb') as fid:
dump(obj, fid, protocol)
except SystemError as exception:
if exception.args[0] == 'error return without exception set':
if os.path.exists(dest):
os.remove(dest)
raise IOError("An error occurred while pickling. This could be "
"due to an attempt to pickle an array (or NDVar) "
"that is too big. Try saving several smaller arrays.")
else:
raise


def map_paths(module_name, class_name):
Expand Down

0 comments on commit 0b67a6e

Please sign in to comment.