From 7387b2c60c21919bda6e18412a4704c3e569307b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 13 Jan 2016 10:51:07 +1600 Subject: [PATCH] Re: Crash with Python bindings --- 00/5a97d6c0de625b8c2c53a69f40047dc5127d56 | 158 ++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 00/5a97d6c0de625b8c2c53a69f40047dc5127d56 diff --git a/00/5a97d6c0de625b8c2c53a69f40047dc5127d56 b/00/5a97d6c0de625b8c2c53a69f40047dc5127d56 new file mode 100644 index 000000000..7e42d4f99 --- /dev/null +++ b/00/5a97d6c0de625b8c2c53a69f40047dc5127d56 @@ -0,0 +1,158 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 748216DE1763 + for ; Tue, 12 Jan 2016 10:53:12 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.009 +X-Spam-Level: +X-Spam-Status: No, score=0.009 tagged_above=-999 required=5 tests=[AWL=0.110, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Brq3eumAHnCS for ; + Tue, 12 Jan 2016 10:53:10 -0800 (PST) +Received: from resqmta-po-12v.sys.comcast.net (resqmta-po-12v.sys.comcast.net + [96.114.154.171]) + by arlo.cworth.org (Postfix) with ESMTPS id D6D186DE1749 + for ; Tue, 12 Jan 2016 10:53:09 -0800 (PST) +Received: from resomta-po-06v.sys.comcast.net ([96.114.154.230]) + by resqmta-po-12v.sys.comcast.net with comcast + id 56t71s0034yXVJQ016t9os; Tue, 12 Jan 2016 18:53:09 +0000 +Received: from mail.tremily.us ([73.221.72.168]) + by resomta-po-06v.sys.comcast.net with comcast + id 56r71s00B3dr3C9016r7gE; Tue, 12 Jan 2016 18:51:09 +0000 +Received: by mail.tremily.us (Postfix, from userid 1000) + id 3C4A61B46A23; Tue, 12 Jan 2016 10:51:07 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin; + t=1452624667; bh=9KQIevMJFlLFN6eNLg0J986b/sfueKfcR89hjZf5BJk=; + h=Date:From:To:Cc:Subject:References:In-Reply-To; + b=ndpbuq09968eG+lxKq16ezp+2wZj/rd1mpL0l+bWxymMmlXrDIOh0ba93eLovewj5 + 5R8Ug0r3CoYeiJb3nOATELlg8Bfjx81TV/uCaUxX65xLpJBzatup213n0zGARvgOQp + MOCUK00r971T060m7SQWUlV+Qm9jUoSx26gvJqKY= +Date: Tue, 12 Jan 2016 10:51:07 -0800 +From: "W. Trevor King" +To: Konrad Hinsen +Cc: notmuch@notmuchmail.org +Subject: Re: Crash with Python bindings +Message-ID: <20160112185107.GA21580@odin.tremily.us> +References: <5694CA65.8010400@fastmail.net> + <20160112102329.4269.20741@thinkbox.jade-hamburg.de> + +MIME-Version: 1.0 +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; boundary="YiEDa0DAkWCtVeE4" +Content-Disposition: inline +In-Reply-To: +OpenPGP: id=39A2F3FA2AB17E5D8764F388FC29BDCDF15F5BE8; + url=http://tremily.us/pubkey.txt +User-Agent: Mutt/1.5.23 (2014-03-12) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; + s=q20140121; t=1452624789; + bh=E4aoHYRBt7W+gLYX6FangOlEfjZh/14hMvL9kTPBuLI=; + h=Received:Received:Received:Date:From:To:Subject:Message-ID: + MIME-Version:Content-Type; + b=ATZbjW8SGozesO+UsqNPvxVZE7/355bAI3j254gIhKfT+U7YYqoGZOxPFZ3v7Jxyu + onNbENuRbj61B0ljo6kBJzRQAVqXUaISwwVV37x5pqmeOr99CtLUpNwtwZTtWaW6fp + DnVgSfa5K4/gT3w7/+1he5y0IgRs6q2WVYSOI6uHp9Iovl25b+35ZOGeWfVE37PH73 + vtkNlO9rWRC1rsSGqcPdlXDcQytClVir4/sgFxtia94azbTuMQSdXigyJZa6xStw7F + chn/V6MbHnM1oyQQ9ygB0jnuaLVVRtfpj5pWSgX1S2zkVLO4KlI9zcI7QUI8bjccit + IH5s9xU/XROSQ== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 12 Jan 2016 18:53:12 -0000 + + +--YiEDa0DAkWCtVeE4 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +Content-Transfer-Encoding: quoted-printable + +On Tue, Jan 12, 2016 at 03:23:46PM +0100, Konrad Hinsen wrote: +> Hi Justus, +>=20 +> > 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. +>=20 +> That reminds me of a recent change in object finalization in Python +> 3: +>=20 +> 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 =3D Database() + q =3D 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@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) + +--=20 +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 + +--YiEDa0DAkWCtVeE4 +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v2 + +iQIcBAEBAgAGBQJWlUsXAAoJEAPqygegUbGs6PMQAILKu849YAttgTVyM3nar0nK +rA5n0pN+NcnMml88pxRJdc3knL94qmhz89mHk2WFrFqBtodg5D3pnEhgaC+sSG23 +63gzTfhAQr98Kjb/R83qnwaulAQKd0Ed0QBNIb9sr0DTs35L4aVwlNnn1ducQqT5 +SAUT5uJVMoaaNs9YgNWPN4ov8xN2LdyyA5CYXICn8ZdYqLkJZdAe8QHGW40oQKhY ++ERs+wqQQrcxh9REHJ/jZqp4BK3ocL/ULzXVsS5ZhWTZ8K4WIA3y9Nh5eao7bDbm +RduCp3md33Qbw8CnN1zPQJ1XyE4EjK8D0T9+l95kBbBd05R50kKhLWNd/ItTcgn1 +Yc9dVOa8itfV8w3KaztlzlSfLTA6Y2P+P5qq33XjKR61n0WNm5QvPWfQp1kpIxyU +k/TlpvbqajMGSOnWLbQZ1XReDCF7taPuoqBknZ02w9hhu8MErGYoQpQiae30a9f9 +2YBrourPhW+CXg0Wmqb3z3/uCp7vwUpxA1WgspWueJQSwgG/NgPkYZtb/tqwZe2X +GZsOL3XCZnpSpWsI4Ow82lr1Gj2QhAgJDdZsjhnewCoYyDnTVf0cLDLJxfyKuJCF +0vWAfdhoHjkdIaf6GUGsElSa/7xn0JmlrJeOe7wMRoaasQLjEaaWvQXoeVzBf2YC +CMkNlG1aP5R4egGJjBlg +=b5g/ +-----END PGP SIGNATURE----- + +--YiEDa0DAkWCtVeE4-- -- 2.26.2