threading and timeouts

Donn Cave donn at oz.net
Thu Nov 25 21:55:37 CET 1999


Quoth Piers Lauder <piers at cs.su.oz.au>:
| Are timeouts possible inside threads?
|
| Eg: escaping from an attempt to use smtplib.SMTP().sendmail() inside a
| child thread if the remote host is being extremely slow.
|
| It doesn't seem possible to use the traditional signal(SIG_ALRM,...)
| approach because signals only work inside the main thread.
|
| The only option I can think of is to re-write the smtplib module to use
| `select', but does anyone know of a simpler solution?

Note that the select option gets even more complicated if it's going
to time out the connect as well as the actual SMTP I/O.  To my vague
recollection this requires a non-blocking socket, don't think I have
ever done it myself but have seen it discussed here.

Maybe you could use two threads, the first just to start the second
which does all the work.  Meanwhile the first can "join" the thread
with a timeout, and if it hits the timeout it can do something (like
close the socket) that will insure the death of the work thread.
That last part sounds very OS-dependent to me.

Hope I'm not too confused over the threading API, haven't had any
opportunity to use it yet since the threads in my programs come out
of the OS itself.  But I guess I have to solve this same SMTP timeout
problem myself, now that you mention it.

	Donn Cave, donn at oz.net




More information about the Python-list mailing list