[Python-ideas] {Python-ideas] C-API exposure

Nick Coghlan ncoghlan at gmail.com
Wed Mar 30 06:00:47 CEST 2011


On Wed, Mar 30, 2011 at 5:32 AM, Sturla Molden <sturla at molden.no> wrote:
> from contextlib import contextmanager
> import ctypes
> _Py_Ticker = ctypes.c_int.in_dll(ctypes.pythonapi,"_Py_Ticker")
>
> @contextmanager
> def atomic():
>     tmp = _Py_Ticker.value
>     _Py_Ticker.value = 0x7fffffff
>     yield
>     _Py_Ticker.value = tmp - 1

Yikes, at least stick a try-finally in there!

If you must practice evil, practice safe evil ;)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list