Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31251

Re: __builtins__ thread-safe / __builtins__ as function?

References <CAAj3U_Ce+F6u+mhUy+_3uNXp4ck2QXtUw+7VG4wo9H88hJs0pQ@mail.gmail.com> <50772BEA.309@davea.name> <CAAj3U_AhyqLaCFNX8QbnkiY0pPec15BPxZr5DJ2bbKmgZ8PYUQ@mail.gmail.com>
Date 2012-10-15 01:01 +1100
Subject Re: __builtins__ thread-safe / __builtins__ as function?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2176.1350223284.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Oct 14, 2012 at 9:36 PM, Juergen Bartholomae
<bartholomae.juergen@googlemail.com> wrote:
> Unfortunately, replacing __builtins__ at import time won't do, because
> external modules (that is, .py) get imported only once when they are
> accessed by the first thread, which includes (of course) setting up of
> __dict__ and __builtins__. When a second thread later accesses this
> module, it has the same variables in __builtins__ that were added by
> the same module in first thread

Sure. But if they're using __builtins__ by name, then you can simply
replace that with something that checks a thread id and responds with
that thread's dictionary. There's no particular reason for
__builtins__ to be a module (as far as I know!), so you should be able
to replace it with an object of your own class.

I think DaveA's recommendation is good. Make a "Version 2.0" of your
system, with a different way of doing global state.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: __builtins__ thread-safe / __builtins__ as function? Chris Angelico <rosuav@gmail.com> - 2012-10-15 01:01 +1100

csiph-web