How to use two threads (GUI and backend)

Chris Angelico rosuav at gmail.com
Wed Oct 26 09:05:41 EDT 2016


On Wed, Oct 26, 2016 at 11:58 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> In practice, this coherency has been implemented in CPython with a
> global lock (GIL). CPython programs are effectively single-threaded.
> They only let go of the lock when they are performing a system call.
>
> 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.

pozz, a classic worker model like you're suggesting will be fine IMO. Go for it.

ChrisA



More information about the Python-list mailing list