[Python-ideas] easy thread-safety [was: fork]

Sven R. Kunze srkunze at mail.de
Tue Aug 18 19:17:58 CEST 2015


On 18.08.2015 18:55, Chris Angelico wrote:
> The notion of "a completely separate heap for each thread" is talking
> about part B - you need a completely separate pile of objects.

Right. However, only if needed. As long as, threads only reads from a 
common variable, there is no need to interfere.

I would except the same behavior as with class attributes and instance 
attributes. The latter overlay the former once they are assigned. 
Otherwise, the former can be read without an issue.

> And if you're going to do that, you may as well make them separate processes.

Consulting the table elaborated on the other thread "Concurrency 
Modules", that is not entirely true.

I agree, behavior-wise, processes behave almost as desired (relevant 
data is copied over and there are no shared variables).

However, regarding the cpu/memore/communication footprint for a new 
process (using spawn) is enormous compared to a thread. So, threading 
still have its merits (IMHO).

> 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.

> 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.

Yep, thanks a lot, Chris. :)

Best,
Sven


More information about the Python-ideas mailing list