To Thread or not to Thread....?

Antoine Pitrou solipsis at pitrou.net
Wed Dec 1 10:04:55 EST 2010


On Wed, 1 Dec 2010 23:48:38 +1000
James Mills <prologic at shortcircuit.net.au> wrote:
> Surely I2C is just a serial-like interface
> and one should be able to do async I/O on it ?
> 
> The use of threads is not necessary here and the GIL
> doesn't become a problem in async I/O anyway.

Well, you are missing the point. The OP wants to do operations that
have certain latency requirements while doing other operations "in
parallel". Using several preemptively-switching threads (or processes)
is the simplest way of achieving that; you can do cooperative
multithreading (which is conceptually the same as single-threaded async
programming), but you'll have to insert as many explicit
synchronization points as necessary to achieve the latency objectives.
Not very practical obviously.

(and, yes, the GIL amounts to some bastardized, fine-grained form of
cooperative multithreading, which is why separate processes might be a
better answer if the latency requirements are tight - especially on
Python 2.x-3.1 where the GIL is badly implemented)

Regards

Antoine.



More information about the Python-list mailing list