Is there a way to globally throw MemoryError exceptions so that the library can clear the caches rather than letting MemoryError see the user code?
I am developing a memory caching library in Python that stores very large objects, to the extent that users usually need to use all available RAM to simplify their scripts and / or speed them up. I would like to have a hook where the python interpreter requests a callback function to free some RAM as a way to avoid calling a MemoryError in the user code.
OS: Solaris and / or Linux
Python: cPython 2.6. *
EDIT: I am looking for a mechanism that will not be processed except for the block. If for any reason a memory error occurred in any code, I would like the Python interpreter to try to use the callback to release some RAM and never throw a MemoryError exception. I do not control the code that will generate errors, and I would like my cache to aggressively use as much RAM as it wants, automatically freeing up RAM as necessary in the user code.
. , MemoryError, , , , , , , OOM- , .
, , , MemoryError, - , , 32- .
, , , . , , , , . , , , , , .
, , , , .
A MemoryError , except.
MemoryError
except
... MemoryException , , , . , ulimit . , , , (, , , ).
, - , , . , , , ! , ( ) .
:
sys.excepthook = <your_exceptionhook>
- , . , traceback.format_exception(), python stderr .
NB: , MemoryException, .
Source: https://habr.com/ru/post/1770794/More articles:Undefined enumeration reference - c ++How to submit a form in a child HTML window, then call the Javascript function in the parent window, and then close the child window - javascriptMicrosoft.Office.Interop.Excel with "bad value" as default parameters - c #Javascript date format to match rails formats - javascriptHow can I store an RPG program in memory? - ibm-midrangeSQL Server: need to add primary key - sqlProblem with data binding in C # - c #Visual Studio Debugger - визуализация Intel Quadruple precision (_Quad) - c++Search for multiple keywords for a dictionary - comparisonHow do Rails controllers share instance variables with views? - ruby-on-railsAll Articles