[Python-ideas] easy thread-safety [was: fork]
Chris Angelico
rosuav at gmail.com
Tue Aug 18 18:55:20 CEST 2015
On Wed, Aug 19, 2015 at 2:28 AM, Sven R. Kunze <srkunze at mail.de> wrote:
> My point was:
>
> 1) processes are fine (more or less)
> 2) threads aren't because their are hard to manage, so let's make them
> easier
>>
>> Finally, just making variables thread-local wouldn't help. You'd need a
>> completely separate heap for each thread;
>
> So?
>
> At this point, talking about internal implementation hardly seems to
> relevant. Not exactly sure, what you mean by heap here, but I could imagine
> more like a overlay approach. As long as, I only read the original variable,
> we are fine. But setting it would require me to store the thread-local value
> somewhere else.
Python has two completely distinct concepts that, together, make up
the whole variable pool:
a) Names, which live in scopes and are usually bound to objects
b) Objects, which are always global and may refer to other objects
Names may be built-ins, module globals, class attributes, or function
locals. The latter exist on a stack, where you can access only the
current function call, and all others are shadowed; also, tighter
forms shadow broader forms (eg a function-local 'str' will shadow the
built-in type of that name).
Objects exist independently of all scopes. Names in multiple scopes
can simultaneously be bound to the same name, and objects can
reference other objects. Objects can never reference names (though
some name bindings are implemented with dictionary lookups, cf
globals() for example).
So far, I think everyone on this list understands everything I've
said. Nothing surprising here; and nothing that depends on a
particular implementation.
The notion of "a completely separate heap for each thread" is talking
about part B - you need a completely separate pile of objects. And if
you're going to do that, you may as well make them separate processes.
There's no way to make module globals thread-local without making the
module object itself thread-local, and if you do that, you probably
need to make every object it references thread-local too, etc, etc,
etc.
Does that answer the questions? Apart from "heap" being perhaps a term
of implementation, this isn't about the internals - it's about the
script-visible behaviour.
ChrisA
More information about the Python-ideas
mailing list