question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better file open/closing in `create`

See original GitHub issue

In testing loompy I’ve had to rerun several times because I made an error in the input, but when I rerun, I get OSError because the hdf5 file was opened and never closed. The file should get closed when errors happen during create

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<timed exec> in <module>()

~/miniconda3/envs/loom-env/lib/python3.6/site-packages/loompy/loompy.py in create(filename, matrix, row_attrs, col_attrs, file_attrs, chunks, chunk_cache, dtype, compression_opts)
   1022 
   1023         # Create the file (empty).
-> 1024         f = h5py.File(name=filename, mode='w')
   1025         f.create_group('/layers')
   1026         f.create_group('/row_attrs')

~/miniconda3/envs/loom-env/lib/python3.6/site-packages/h5py/_hl/files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
    267             with phil:
    268                 fapl = make_fapl(driver, libver, **kwds)
--> 269                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
    270 
    271                 if swmr_support:

~/miniconda3/envs/loom-env/lib/python3.6/site-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    103         fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
    104     elif mode == 'w':
--> 105         fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
    106     elif mode == 'a':
    107         # Open in append mode (read/write).

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.create()

OSError: Unable to create file (unable to truncate a file which is already open)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:31 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
slinnarssoncommented, Feb 8, 2018

No let’s leave the current behaviour for create, i.e. to overwrite. This is close to how open works in Python, so is expected behaviour. Changing it will break a lot of code, unless you make the option default to True, in which case it will not catch any mistakes anyway.

1reaction
slinnarssoncommented, Feb 8, 2018

Good point (timestamp). I fixed it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it more efficient to rewind a file than closing it and opening it ...
I'm asking about opening, closing and "rewinding" files in general, so it's aplicable to other big projects were performance and memory may ...
Read more >
Python Tutorial - File and Text Processing
1.1 Opening/Closing a File. open(file, [mode='r']) -> fileObj : Open the file and return a ... To create temporary files/directories, use tempfile module....
Read more >
Opening, Closing, and Saving Files | FileMaker Basics
Figure 3.35 To create a new file, choose File > New Database. Closing a file. Because FileMaker automatically saves your data, closing a...
Read more >
Mac Automation Scripting Guide: Watching Folders
With folder actions, you can create automated workflows that: Notify you when new files and folders arrive in a folder.
Read more >
Workspace and Files
“Local workspace” refers to what is loaded or created in R's memory that can be ... Explorer or Mac Finder and opening/closing folders...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found