Re: Crash with Python bindings

Subject: Re: Crash with Python bindings

Date: Tue, 12 Jan 2016 10:51:07 -0800

To: Konrad Hinsen


From: W. Trevor King

On Tue, Jan 12, 2016 at 03:23:46PM +0100, Konrad Hinsen wrote:
> Hi Justus,
> > So I guess what happens is that Python3 changed how the
> > interpreter environment is torn down and they actually destroy the
> > 'q' object.  If that is so, then your data is indeed safe.
> That reminds me of a recent change in object finalization in Python
> 3:

I'm pretty sure that is what's going on.  The PEP landed in Python
3.4, explaining why I don't see this issue in 3.3 [1].  And it has

   In particular, this PEP obsoletes the current guideline that
   "objects with a __del__ method should not be part of a reference

I'm not sure what the best way is to fix __del__ in our Python
bindings, but if you manage them explicitly:

  db = Database()
  q = Query(db, "*")
  del q
  del db

you can avoid the abort (which happens when q.__del__ is called after
db.__del__).  We could make that sort of cleanup easier with context
managers for Query objects (we have them for databases since [3]), and
they look like the only object that keep an internal database

  with Database() as db:
    with Query(db, "*") as q:
      # do something with q


[3]: 36ce7e3c (python: implement the context manager protocol for
     database objects, 2012-02-15, v0.12)

This email may be signed or encrypted with GnuPG (
For more information, see
signature.asc (application/pgp-signature)