Skip to content

How safe is it to open NWBs without a context manager? #41

Answered by oruebel
jonahpearl asked this question in Q&A
Discussion options

You must be logged in to vote

Specifically, is it possible to end up with a corrupted HDF5 file if the kernel crashes unexpectedly while reading from a file that's opened like this?

No, opening a file with mode 'r' enforces that no changes are being made to the file and as such the file cannot be corrupted.

as opposed to using a context manager. Is this best practice?

For read it is common because on read users often need to perform a large number of read operations on the same file that do not nicely fit into a context manager. To avoid opening and parsing the file for every read, the file is typically opened until the end of the analysis. The file should then be closed explicitly (note files are also closed auto…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@jonahpearl
Comment options

@rly
Comment options

rly Feb 3, 2023
Maintainer

Answer selected by jonahpearl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants