[Tutor] demon / app I/F better way ?

Alan Gauld alan.gauld at freenet.co.uk
Mon Nov 15 08:01:30 CET 2004


> I don't think any of the complications Alan suggests are needed. The
> Queue module takes care of the necessary locking semantics. It is
> specifically intended for inter-thread communication. From the docs:

I've never usd the psarticular Queue module you refer to and
it may well solve the problems. Indeed the socket/pipe approach
also caters for all of those issues. I was talking in general
terms and most of the isses apply to any inter-process comms
mechanism.

> I'm starting to think there is a cultural bias against threads in
the
> python community. I came to Python from Java where threads are
commonly
> used.

And cause lots of problems. The correct and safe use of threads
in any language is fraught with difficulty. I spend a fair amount
of any given year disentangling problems brought about by over
zealous use of threads in designs (mostly in Java). When used
properly threads are immensely powerful tools but to be safe
you do need to consider very carefully all theramifications
of state, locking and resilience/failover.

But used correctly they are great. I built a telephone exchange
system several years ago which was fully threaded in operation
- each call was a thread - and it handled huge volumes without
a hickup. I certainly wish Microsoft would use more threading
than they do in Windows - it would reduce the number of
application hangups I get!

But for beginners threads are a difficult concept to grok and
can be a nightmare to debug and on that basis I usually look for
simpler options before recommending them to beginners. Like
somebody in the XP movement once said, always pick the simplest
thing that will work.

> This is the second time I have suggested a threaded solution to a
> problem posted on this list. Each time someone has fired back a
reply
> about the difficulties of threading. The replies surprise me because
in
> my experience, simple uses of threads can be, well, simple.

Simple uses can be, but unfortunately there are very few simple uses
of threads.

> are dangers, and certainly it can be hard to wrap your head around a
> threaded app, but with a little care and the help of some library
> classes you can get a lot done easily.

Absolutely, and it is good to include threads as an option. Often
they are the best solution. But on this list, aimed at beginners,
its worth having a variety of options to pick from.

Alan G



More information about the Tutor mailing list