Thread-safe sockets?

Aahz aahz at pythoncraft.com
Sat Apr 13 13:38:01 EDT 2002


In article <slrnabg28s.g9m.mlh at vier.idi.ntnu.no>,
Magnus Lie Hetland <mlh at vier.idi.ntnu.no> wrote:
>
>I'm working with a ThreadedTCPServer and the following question came
>up: Is it safe for two different threads to use the
>StreamRequestHandler's rfile and wfile simultaneously? (I.e. one
>thread reads and another writes -- no simultaneous reading or
>writing.) These file-like objects are created with the socket.makefile
>method.
>
>Since the two operations seem so unrelated, it would also seem that
>this is safe -- but I'm worried that there may be (perhaps
>paltform-dependent) thread-unsafe interference between the two at some
>lower level. Does anyone know?

I don't know -- but I wouldn't do it.  Unless rfile and wfile are
physically two separate sockets, I would expect cross-platform problems
even if I saw it working somewhere.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?



More information about the Python-list mailing list