Trying to robustly patch func.__globals__

Sorry yeah I spoke imprecisely, that is exactly what I did originally when I was doing a pure python module. In C nothing prevents reassigning func->func_globals although I’m not sure how kosher this is. Since I do it from PyFunction_AddWatcher callback as soon as the function is created I think there’s no time for any other python code to observe the difference.

Yep I also posted about that shortly after this :slight_smile:

This is an interesting idea. I think you can probably break it even within one thread though, because you could call other functions before you return that might expect to see changes in globals right away.

1 Like