diff --git a/binarycpython/utils/dataIO.py b/binarycpython/utils/dataIO.py index 1bcf59a7a3b35d044263f23e59d55621fb90876e..f6e8990bcb38170cb182d2cbfbd72b717874e320 100644 --- a/binarycpython/utils/dataIO.py +++ b/binarycpython/utils/dataIO.py @@ -634,8 +634,7 @@ class dataIO(): # error on open should be fatal except Exception as e: - if vb: - print("Error in locked_open_for_write() : {}".format(e)) + print("Error in locked_open_for_write() : {}".format(e)) if fatal_open_errors: if vb: print("fatal exit on open") @@ -677,25 +676,40 @@ class dataIO(): """ Wrapper for open() with automatic compression based on the file extension. """ + if compression is None: compression = self.compression_type(file) + print("open() with mode = {mode}, compression {compression}".format( + compression=compression, + mode=mode)) if compression: if compresslevel is None: compresslevel = 9 + if not 'b' in mode: + # if we don't specify binary-mode, the gzip module + # defaults to binary, which isn't compatible with JSON, + # so default to text if not specified otherwise + mode += 't' + else: + encoding = None + errors = None + newline = None if compression is "bzip2": file_object = bz2.open(file, mode=mode, compresslevel=compresslevel, encoding=encoding, - error=errors, - newline=newline) + errors=errors, + newline=newline + ) elif compression is "gzip": file_object = gzip.open(file, mode=mode, compresslevel=compresslevel, encoding=encoding, - error=errors, - newline=newline) + errors=errors, + newline=newline + ) else: file_object = open(file, mode=mode, diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 4b1ec7011c5d50ee6ad5f51fccb455ed79fdd9d4..39441f43b6e389e815f8ec293420443112140a0b 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -622,8 +622,11 @@ class Population(analytics, settings_name ) + print("ok") + # open locked settings file, then output if we get the lock - (f,lock) = self.locked_open_for_write(settings_fullname) + (f,lock) = self.locked_open_for_write(settings_fullname,vb=True) + print("ok") if lock and f: self.verbose_print( @@ -638,7 +641,9 @@ class Population(analytics, default=binaryc_json_serializer, ensure_ascii=ensure_ascii ) + print("ok pre") self.locked_close(f,lock) + print("ok ret") return settings_fullname else: msg = "Exporting all info without passing a value for `outfile` requires custom_options['data_dir'] to be present. That is not the cause. Either set the `data_dir` or pass a value for `outfile` "