C API: Making a context manager

Chris Kaynor ckaynor at zindagigames.com
Tue Nov 1 12:19:46 EDT 2011


On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Chris Kaynor, 31.10.2011 19:34:
>>
>> I am currently rewritting a class using the Python C API to improve
>> performance of it, however I have not been able to find any
>> documentation about how to make a context manager using the C API.
>
> You should take a look at Cython. It makes these things *so* much easier.

Unfortunately, all of the code has to be fully compatible with CPython
2.6 - it needs to function inside of Maya, which has CPython 2.6
embedded, and to which we do not have the source code.

While not all parts of our code base are used inside of Maya, most of
the performance-critical items are to some degree or another.

In this particular case, the connected context manager is not heavily
used (outside of unittests) and itself is not performance critical,
but the much of the rest of the package (and thus the class) it is
part of is.

Chris



More information about the Python-list mailing list