threading

Marko Rauhamaa marko at pacujo.net
Mon Apr 7 01:46:15 EDT 2014


Paul Rubin <no.email at nospam.invalid>:

> I keep hearing about all the perils of threading bugs and it just
> hasn't happened to me in Python as far as I know.

Good for you. I'm saying the first step to thread-safe code is to have a
healthy fear of the perils.

> The main trick is to not share any mutable data between threads.
> Instead have them communicate by message passing through Queues.

That certainly is a good way and is akin to multiprocessing. You still
need to make sure you don't flood the queues or cause deadlocks by
limiting queue sizes.

It is still easy to accidentally pass references to mutable objects
between threads (and most people don't even try to avoid it).
Multiprocessing naturally enforces the principle.


Marko



More information about the Python-list mailing list