Forked from cpascual/h5_create_read_write_issue.py
Created
September 4, 2018 06:29
-
-
Save enricmcalvo/80a9c74cba35707a25d632dfe7d6fd43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import numpy | |
import time | |
import sys | |
from multiprocessing import Process | |
FNAME = 'foo.h5' | |
class Reader(Process): | |
"""Just a process that opens the file for reading and keeps it open | |
Note: I use a separate process to avoid a "File already Open" exception | |
""" | |
def run(self): | |
print("READER: Open file for read") | |
f = h5py.File(FNAME, 'r', libver='latest') | |
time.sleep(100) | |
f.close() | |
def open_for_read(): | |
""" open the file for read and keep it open""" | |
reader = Reader() | |
reader.start() | |
time.sleep(1) # just give time to the reader to open before continuing | |
return reader | |
def initialize_file(): | |
"""create a file containing a dataset""" | |
f = h5py.File(FNAME,'w', libver='latest') | |
f.create_dataset('data', data=numpy.arange(5)) | |
f.close() | |
def open_for_append(): | |
"""open the file for appending""" | |
f = h5py.File(FNAME, 'a', libver='latest') | |
f.close() | |
if __name__ == '__main__': | |
print("hdf5_version=", h5py.version.hdf5_version) | |
initialize_file() | |
reader = open_for_read() | |
try: | |
# open for append while it is open for read by another process | |
# fails with hdf5_version=1.10.0 (but not with 1.8.16) | |
open_for_append() | |
finally: | |
reader.terminate() | |
print("OK. Finish") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment