Crash with Python bindings
W. Trevor King
wking at tremily.us
Tue Jan 12 10:51:07 PST 2016
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:
>
> https://www.python.org/dev/peps/pep-0442/
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
[2]:
In particular, this PEP obsoletes the current guideline that
"objects with a __del__ method should not be part of a reference
cycle".
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
db.close()
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
reference:
with Database() as db:
with Query(db, "*") as q:
# do something with q
db.close()
Cheers,
Trevor
[1]: id:20160112180813.GA20499 at odin.tremily.us
[2]: https://www.python.org/dev/peps/pep-0442/#impact
[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 (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20160112/87acaa89/attachment.sig>
More information about the notmuch
mailing list