How to use two threads (GUI and backend)

Marko Rauhamaa marko at pacujo.net
Wed Oct 26 09:37:36 EDT 2016


Chris Angelico <rosuav at gmail.com>:

> On Wed, Oct 26, 2016 at 11:58 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> I can't think of a valid program that could take advantage of this
>> primitive guarantee of Python's. For example, there is no "volatile"
>> in Python so you can't coordinate Python threads safely without
>> proper synchronization. If you set a variable in one thread and read
>> it in another thread, the latter might never see the change.
>
> Incorrect. If you set something in one thread and read it in another,
> it WILL see it, just as it would with any other way of running two
> functions. (Obviously function locals won't be seen, because they
> never will.) Global state is shared across all threads.

I don't know what "Global state is shared across all threads" means in
this context. It sounds like something that would be true for, say, Java
and C as well. However, those languages don't promise to propagate
improperly synchronized changes between threads.

Now I would like to ask for some documentation.


Marko



More information about the Python-list mailing list