[Twisted-Python] Synchronized FileDescriptor is bad
glyph at twistedmatrix.com
Thu Aug 16 22:08:41 EDT 2001
On Thu, 16 Aug 2001, Itamar wrote:
> The fact that FileDescriptor is synchronized may lead people to think
> it's thread safe, and it's not (connectionLose not being thread safe
> even when syncrhonized isn't based not only on conjecture but on actual
> observed errors.)
> I think no code should be synchronized in threaded mode unless you
> absolutely know that it will thereby be made thread safe. Otherwise,
> what's the point? It's the equivalent of wrong documentation, and it
> slows things down.
> Since there is now a generic mechanism for running non-thread safe code
> from threads (the threadtask module), there is no problem with this.
Sorry for neglecting this thread safety stuff, but I've been very busy
with other changes (which, somewhat ironically, will need to be thread
safe). I should have given you the go-ahead to fix it completely much
I assume you're talking about connectionLost, and yes, it's misleading and
wrong. It should never be called from user code, and always happen in the
I apologize for the state of the threading code; as you can probably tell,
it was written when I was fresh from Java and still recursive-mutex happy.
Please integrate your changes when it's next convenient, including the
removal of any synchronization that you find inappropriate, and
alternative implementations of various currently-synchronized classes. I
recommend you take a look at threadable.dispatchOS as well... it could
probably use the threadtask mechanism.
If you're feeling _especially_ generous, feel free to write a document
entitled "threaded programming with twisted" that gives a nice overview of
what's appropriate to use threads for, and what things they can and can't
do using your thread safety scheme :-).
______ __ __ _____ _ _
| ____ | \_/ |_____] |_____|
|_____| |_____ | | | |
@ t w i s t e d m a t r i x . c o m
More information about the Twisted-Python