Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37720
| Date | 2013-01-26 15:14 +0200 |
|---|---|
| From | hyperboreean <hyperboreean@nerdshack.com> |
| Subject | Cancel threads after timeout |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1073.1359207608.2939.python-list@python.org> (permalink) |
Here's the use case I want to implement - I have to generate a report from multiple database servers. This report should be generated every 2 hours. Sometimes it happens that a query on one of the database servers takes longer than expected and impedes the generation of this report (that's right, the queries are ran sequential). What I am trying to achieve is to parallelize the queries on each database server and to be able to cancel one of them if it takes longer than X minutes. threading.Thread doesn't support this and seems that in general programming languages don't implement a way to cancel threads from the outside. Now, I've read all the stackoverflow threads about killing a thread, canceling a thread after a timeout, but all of them imply that you are able to check from within the thread if you should end the computation or not - that's not really my case, where the computation is a SQL query. So, what I have in mind is something like: the main loop starts a threading.Thread which in turn is responsible for starting another thread in which the actual computation happens (could be a threading.Thread or a multiprocessing.Process) *and* checks if the specified timeout has passed. If the time is up, it exits, letting the main loop know. Lots of words, no code - let me know if you have any suggestions, ideas to this rant. Thanks!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Cancel threads after timeout hyperboreean <hyperboreean@nerdshack.com> - 2013-01-26 15:14 +0200
csiph-web