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 dmalcolm
Recipients dmalcolm, pitrou
Date 2010-10-26.00:23:42
SpamBayes Score 2.4694097e-10
Marked as misclassified No
Message-id <1288052629.43.0.603183515135.issue10195@psf.upfronthosting.co.za>
In-reply-to
Content
We were chatting on #python-dev on possible ways of testing the correct handling of "MemoryError".

Attached is one idea: adding a sys._inject_malloc_failure() hook, letting you inject a memory-allocation (or reallocation) failure some number of allocations in the future:

>>> import sys
[52733 refs]
>>> 2 + 2
4
[52733 refs]
>>> sys._inject_malloc_failure(50)
[52733 refs]
>>> 2 + 2
MemoryError
[52747 refs]
>>> 2 + 2
4
[52747 refs]

I'm not sure how to make this useful; perhaps it could instead compare with the "serialno" in Objects/obmalloc.c so that you could set up a specific numbered allocation and have it fail (or perhaps a range of serial numbers, and expose "serialno" within the "sys" module?)

Another idea might be to randomly have some proportion of allocations fail.  Perhaps the test suite could have an option where it runs each set of tests in a separate subprocess, and sets a command-line switch to inject "random" malloc failures? (storing the seed, so that they're reproducible, on one machine at least).
History
Date User Action Args
2010-10-26 00:23:49dmalcolmsetrecipients: + dmalcolm, pitrou
2010-10-26 00:23:49dmalcolmsetmessageid: <1288052629.43.0.603183515135.issue10195@psf.upfronthosting.co.za>
2010-10-26 00:23:47dmalcolmlinkissue10195 messages
2010-10-26 00:23:45dmalcolmcreate