def close_files(self): for name, file in self.file_map.items(): file.close() # on osx and linux this will give random bus errors (osx) or segfaults (linux) # on win32 however, we'll run out of file handles if vaex.utils.osname not in ["osx", "linux"]: for name, memmap in self.mapping_map.items(): memmap.close()
def read_json_or_yaml(file, fs_options={}, fs=None, old_style=True): file, path = vaex.file.file_and_path(file, fs_options=fs_options, fs=fs) try: if path: base, ext = os.path.splitext(path) else: ext = '.json' # default if ext == ".json": return json.load(file, cls=VaexJsonDecoder if old_style else None) or {} elif ext == ".yaml": return yaml_load(file) or {} else: raise ValueError("file should end in .json or .yaml (not %s)" % ext) finally: file.close()
def write_json_or_yaml(file, data, fs_options={}, fs=None, old_style=True): file, path = vaex.file.file_and_path(file, mode='w', fs_options=fs_options, fs=fs) try: if path: base, ext = os.path.splitext(path) else: ext = '.json' # default if ext == ".json": json.dump(data, file, indent=2, cls=VaexJsonEncoder if old_style else None) elif ext == ".yaml": yaml_dump(file, data) else: raise ValueError("file should end in .json or .yaml (not %s)" % ext) finally: file.close()
def close(self): for name, memmap in self.mapping_map.items(): memmap.close() for name, file in self.file_map.items(): file.close()