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.

Adding a close() method

See original GitHub issue

This a request that came up many times on the old pyrocksdb repo, but was never implemented. The reasoning seemed off to me. Without a close() method, there really is no way to guarantee a lock is released as Python’s garbage collection can’t fully be relied on for this.

If you’re consistently recreating databases from scratch (as I am in my use-case), this really complicates things. Any chance such a method can be added?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
askcommented, Oct 3, 2017

I’d say this is a pretty important issue for anybody who require graceful shutdown of processes. Relying on del is a horrible practice that should be avoided if possible, and IMHO if necessary even warrants a backward incompatible change.

Doing del(self._db) may work for that specific application, but in general you’d have to carefully del() any other references to the object as well, and who knows what happens if there are circular references.

NOTE: Using a weakref callback you could possibly set a flag to ensure the database was closed (well, implicitly by side effect of being garbage collected, trying to be an optimist here:) pseudocode:

class RocksDBWrapper:
    _db_collected = False

    def open(self):
        self._db = rocksdb.DB(...)
        self._dbref = weakref.ref(self._db, self._on_db_collected)
       
    def _on_db_collected(self, ref):
        self._db_collected = True

    def close(self):
        while not self._db_collected:
            try:
                del(self.db)
            except AttributeError:
                pass
            gc.collect()

I think this is a pretty serious issue that needs to be resolved. Hopefully I, or someone else get some time to look into it.

1reaction
twmhtcommented, Feb 2, 2019

closed due to fix by #40

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python File close() Method
Python automatically closes a file when the reference object of a file is reassigned to another file. It is a good practice to...
Read more >
Reader close() method in Java with Examples
The close() method of Reader Class in Java is used to close the stream and release the resources that were busy in the...
Read more >
Python File close() Method
The close() method closes an open file. You should always close your files, in some cases, due to buffering, changes made to a...
Read more >
JavaScript Window close method
JavaScript provides an in-built function named close() to close the browser window that is opened by using window.open() method. Unlike the window.open() ...
Read more >
Understanding python close method
Python automatically closes a file when the reference object of a file is reassigned to another file. It is a good practice to...
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