This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Trundle, alexandre.vassalotti, amaury.forgeotdarc, brett.cannon, ncoghlan, palm.kevin, pitrou
Date 2011-02-28.00:24:24
SpamBayes Score 2.3255775e-10
Marked as misclassified No
Message-id <1298852665.67.0.366481441492.issue11321@psf.upfronthosting.co.za>
In-reply-to
Content
While Andreas's patch does indeed prevent the crash, there is something more going on here.

I modified his patch to print out the reference counts immediately after the new INCREF commands.

With the INCREF commands commented out, it looks like this:

~/devel/py3k$ ./issue113213.3
START
Try import #0 ...Initialising _pickle
Pickler type references: 10
Unpickler type references: 8
Module initialised
SUCCESS
Try import #1 ...Initialising _pickle
Pickler type references: 10
Unpickler type references: 8
Module initialised
SUCCESS
Try import #2 ...Initialising _pickle
Pickler type references: 9
Unpickler type references: 7
Module initialised
SUCCESS
Try import #3 ...Initialising _pickle
Pickler type references: 8
Unpickler type references: 6
Module initialised
SUCCESS
Try import #4 ...Initialising _pickle
Pickler type references: 7
Unpickler type references: 5
Module initialised
SUCCESS
Try import #5 ...Initialising _pickle
Pickler type references: 6
Unpickler type references: 4
Module initialised
SUCCESS
Try import #6 ...Initialising _pickle
Pickler type references: 5
Unpickler type references: 3
Module initialised
SUCCESS
Try import #7 ...Initialising _pickle
Pickler type references: 4
Unpickler type references: 2
Module initialised
SUCCESS
Try import #8 ...Initialising _pickle
Pickler type references: 3
Unpickler type references: 1
Module initialised
Segmentation fault

Note that it does the right thing the first time Py_Finalize is called, but the reference counts start going down after that.

When the INCREF is included, the count goes up initially and then levels out.

So I believe the simple patch is just masking the problem instead of fixing it. The correct answer is to follow the documentation and implement the module finalisation protocol for _pickle (i.e. move all the static globals into the module struct and implement module traversal and finalisation functions).
History
Date User Action Args
2011-02-28 00:24:25ncoghlansetrecipients: + ncoghlan, brett.cannon, amaury.forgeotdarc, pitrou, alexandre.vassalotti, Trundle, palm.kevin
2011-02-28 00:24:25ncoghlansetmessageid: <1298852665.67.0.366481441492.issue11321@psf.upfronthosting.co.za>
2011-02-28 00:24:24ncoghlanlinkissue11321 messages
2011-02-28 00:24:24ncoghlancreate