[Python-Dev] IO module improvements

Antoine Pitrou solipsis at pitrou.net
Sun Feb 7 16:59:39 CET 2010


Le dimanche 07 février 2010 à 09:54 +0100, Pascal Chambon a écrit :
> > Actually, TextIOWrapper is simply not thread-safe for most of its operations. I
> > think we did the work for simple writing, though, since it's better for
> > multi-threaded use of print().
> 
> Argh, I had the impression that all io streams were theoretically
> thread-safe (although it's not documented so indeed). It needs
> clarification maybe.

It should first be discussed which classes need to be thread-safe. 
There is nothing about it in PEP 3116, and the first (pure Python)
implementation of the io module had no locks anywhere.
We later added locks to the Buffered classes because it seemed an
obvious requirement for many use cases (for example object databases
such as ZODB or Durus).

> > You can, but be aware that _pyio is *really* slow... I'm not sure it would be a
> > service to many users.
> >   
> Hum... would a pure python module, augmented with cython declarations,
> offer a speed similar to c modules ? Maybe I shall investigate that
> way, because it would be great to have an implemntation which is both
> safer and sufficiently quick...

There's no obvious answer. I suspect that it won't be as fast as the
current C implementation, because some things simply aren't possible or
available in Python. But it could be "fast enough". You have to
experiment.

Regards

Antoine.




More information about the Python-Dev mailing list