Message119586
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). |
|
Date |
User |
Action |
Args |
2010-10-26 00:23:49 | dmalcolm | set | recipients:
+ dmalcolm, pitrou |
2010-10-26 00:23:49 | dmalcolm | set | messageid: <1288052629.43.0.603183515135.issue10195@psf.upfronthosting.co.za> |
2010-10-26 00:23:47 | dmalcolm | link | issue10195 messages |
2010-10-26 00:23:45 | dmalcolm | create | |
|