Hi Benjamin,

On Mon, Apr 9, 2012 at 12:42 AM, Benjamin Peterson <benja...@python.org> wrote:
> 2012/4/8 Paul Colomiets <p...@colomiets.name>:
>> Function 'sys.setcleanuphook'
>> -----------------------------
>>
>> A new function for the ``sys`` module is proposed.  This function sets
>> a callback which is executed every time ``f_in_cleanup`` becomes
>> false.  Callbacks get a frame object as their sole argument, so that
>> they can figure out where they are called from.
>
> Calling a function every time you leave a finally block? Isn't that a
> bit expensive?
>

For signal handler it isn't, because you set it only when signal happens,
and remove it when it first happens (in the common case)

For yield-based coroutines, there is a similar overhead of trampoline
at each yield and each return, and exit from finally doesn't happen more
often than return.

For both greenlets and yield-based coroutines it is intented to be used
for exceptional situation (when timeout happens *and* coroutine
currently in finally block), so can be turned off when unneeded
(and even turned on only for this specific coroutine).

When hook is not set it's only checking of single pointer for NULL
value at each exit from finally. This overhead should be negligible.

-- 
Paul
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to