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


Groups > comp.lang.python > #31251 > unrolled thread

Re: __builtins__ thread-safe / __builtins__ as function?

Started byChris Angelico <rosuav@gmail.com>
First post2012-10-15 01:01 +1100
Last post2012-10-15 01:01 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#31251 — Re: __builtins__ thread-safe / __builtins__ as function?

FromChris Angelico <rosuav@gmail.com>
Date2012-10-15 01:01 +1100
SubjectRe: __builtins__ thread-safe / __builtins__ as function?
Message-ID<mailman.2176.1350223284.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web