Disable obviously recursive auditing?

Currently, it is very easy to cause python to hang:

import sys
sys.addaudithook(sys.audit)

Should there be a built-in mechanism to detect and disable simple cases like such? Perhaps raise if an audit hook is triggering an audit with the exact same event and arguments?

There are various ways to crash Python. I don’t think that we have to implement checks to protect the developer from any kind of mistake. It can be inefficient to implement some checks, whereas only a minority would benefit from such checks.

If you consider that it’s non-obvious that sys.addaudithook(sys.audit) can crash, I would suggest updating sys.addaudithook() documentation.

5 Likes