__builtins__ thread-safe / __builtins__ as function?

Chris Angelico rosuav at gmail.com
Thu Oct 11 10:25:27 EDT 2012


On Fri, Oct 12, 2012 at 1:16 AM, Juergen Bartholomae
<bartholomae.juergen at googlemail.com> wrote:
> One possible solution  is to somehow redirect every __builtins__ to a
> function that returns a different __builtins__ dictionary for each thread
> (such a function already exists).

How exactly does the code reference it? If they're simply referring to
the name __builtins__ at module level, you ought to be able to import
the module, then assign some_module.__builtins__ to your thread-local
object, then call code in it as normal.

An interesting problem, and one where monkeypatching is, imho, justified.

ChrisA



More information about the Python-list mailing list