Entry
How can x threads be started at once and stopped y seconds later, processing only the successfully returned threads?
Jun 7th, 2000 05:07
unknown unknown, Gordon McMillan
Answer:
Threads have to stop themselves. You can't "kill" a thread without
jeopardizing the integrity of the process.
For example:
Consider a situation where all the links from multiple URL's must be
retrieved at the same time. By setting a time limit, slow sites don't
slow down the whole process and appropriate error messages are returned
stating which sites weren't completed in y seconds.
Solution:
You need to use a method of retrieving that recognizes time limits. In
your case, you have 3 choices:
- a version of urllib where urlopen uses select with a timeout and
aborts if the timeout expires (Aahz may have done this?).
- a version of urllib that uses non-blocking sockets (then no threads
needed).
- use separate processes instead of separate threads (because you *can*
kill a process and properly release resources).
If none of those options are available to you - just ignore the thread
if it's too slow.