Signals between threads

Parzival Herzog parz at home.com
Mon Feb 12 15:57:01 EST 2001


"Warren Postma" <embed at geocities.com> wrote in message
news:UXSh6.2933$D3.13081 at tor-nn1.netcom.ca...

> In particular, the ability of one thread to send a signal (raise an
> exception in another thread), and for the built-in thread module to return
a
> an object that can be used for this purpose.  (Currently
> thread.start_new_thread returns None. I consider that to be Horrid
> Behaviour, and the module threading.py to be a nice-API, but which should
be
> implemented in Python itself.)
>
> I agree with posters who said that interruptable and "killable" threads
are
> a bad, or dangerous, idea.    I think the ability to inject an exception
> into another thread could easily be abused, however I also think it needs
to
> be there, for when it's essential to getting a job done.

Absolutely: This is the single greatest defect in Python threads. You have
to have a way
to signal threads independent of whether they are blocked. In Modula-3, an
exception,
defined in the threading interface: "Thread.Alerted" is used to accomplish
this. This
makes Modula-3 threads practical to use. Python requires that threads poll
for
exceptional conditions, e.g "while self.keepRunning:" without providing a
guaranteed
way to ensure that the polling loop will actually run (i.e the thread could
be blocked
for abitrary amounts of time in i/O, or in consume arbitrary amounts of time
in computation
before returning to the polling loop. These requirements arise in real
applications that
need to be robust and reliable in an unreliable environment.

So yes, lets have a "thread.alerted" exception!

- Parzival





More information about the Python-list mailing list