Exceptions in threads

Martin von Loewis loewis at informatik.hu-berlin.de
Thu Jan 24 15:30:32 EST 2002


Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> writes:

> I was, perhaps, not clear. onException would be a method of the child
> thread class and execute in that thread.
> 
> Implementing such a scheme in code isn't a problem. What concerns me
> is the scope for exceptions in the thread initialisation (mainly) and
> termination which are outside the controlled block.
> 
> Is it possible, for example, for initialisation to fail owing to a
> memory shortage?

You aren't much clearer here, either: Are you talking to the
initialisation that occurs in the parent thread or the one in the
child thread? If a resource shortage occurs in the parent thread
(e.g. no more threads), it is reported as an exception in the parent
thread.

A resource shortage in the new thread likely means that Python is out
of memory, so badly that it cannot even invoke the .run() method of
the new thread. In that case, why would you expect that it still has
the resources to call the onException function in the same thread?

If you use threading.py, you should be aware that your scheme cannot
possibly work: it is pure Python, so whatever it would do, you could
do yourself, in pure Python, as well. Threads, in module thread, are
no objects, so they don't have methods to call.

Regards,
Martin



More information about the Python-list mailing list