Re: __builtins__ thread-safe / __builtins__ as function?

Discussion in 'Python' started by Chris Angelico, Oct 14, 2012.

  1. On Sun, Oct 14, 2012 at 9:36 PM, Juergen Bartholomae
    <> 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
    Chris Angelico, Oct 14, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. _mario.lat
    Replies:
    9
    Views:
    445
    Richard Tobin
    May 28, 2007
  2. Replies:
    23
    Views:
    870
    Pete Becker
    Sep 18, 2007
  3. Gabriel Rossetti
    Replies:
    0
    Views:
    1,293
    Gabriel Rossetti
    Aug 29, 2008
  4. John Nagle
    Replies:
    5
    Views:
    447
    John Nagle
    Mar 12, 2012
  5. Chris Angelico
    Replies:
    0
    Views:
    140
    Chris Angelico
    Oct 11, 2012
Loading...

Share This Page