[issue33406] [ctypes] increase the refcount of a callback function

Eryk Sun report at bugs.python.org
Wed May 2 05:16:40 EDT 2018


Eryk Sun <eryksun at gmail.com> added the comment:

There isn't a problem in most cases, since functions that take a callback usually call it before returning. If the library does keep a long-lived reference to a callback (e.g. a console control handler in Windows), there are ways to support this, depending on the context (e.g. global variable, class attribute, instance attribute, a dict). 

However, for the case where a callback should remain referenced for the lifetime of the process, it would be convenient to have a `callback_incref` option. Internally this would use a new function flag `FUNCFLAG_CALLBACK_INCREF`.

----------
nosy: +eryksun
title: [ctypes] increase refcount of a CFUNCTYPE instance when passing to a CDLL -> [ctypes] increase the refcount of a callback function
type: behavior -> enhancement
versions: +Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33406>
_______________________________________


More information about the Python-bugs-list mailing list