[Python-ideas] easy thread-safety [was: fork]
Ron Adam
ron3200 at gmail.com
Wed Aug 19 18:57:20 CEST 2015
On 08/18/2015 01:27 PM, Chris Angelico wrote:
>>> 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.
>> >
>> >Something wrong with that? Shouldn't matter as long as there is only a
>> >single thread.
> As long as there's only a single thread, there's no difference between
> process-wide and thread-local. Once you start a second thread,
> something needs to know what objects belong where. That's all.
Just a thought...
What if a new name type, co_mutables, is added to functions objects, and
a new keyword to go with it, "mutable" to be used like "globals" and
"nonlocals". And then raise an error on an attempt to bind a mutable
object to a name not in co_mutables.
Also, don't include co_mutables in functions scopes. That would require
mutable objects to be passed as function arguments to be seen.
Then only mutable objects/names explicitly passed to a new thread need
to be tracked.
It might be possible to turn that on with a compiler directive at the
top of a module so normal python code would work normally, and thread
safe python code would be limited.
Would something in this direction simplify the problem?
Cheers,
Ron
More information about the Python-ideas
mailing list