threading with time limit
Gordon McMillan
gmcm at hypernet.com
Mon Jun 5 17:31:16 EDT 2000
intmktg at Gloria.CAM.ORG (Marc Tardif) wrote in
<Pine.LNX.4.10.10006051515580.30679-100000 at Gloria.CAM.ORG>:
>How can x threads be started at once and stopped y seconds later,
>processing only the successfully returned threads?
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 wheren't completed in y seconds.
Then 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, then you're doing roughly
the right thing - just ignore the thread if it's too slow.
- Gordon
More information about the Python-list
mailing list