Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37720

Cancel threads after timeout

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <hyperboreean@nerdshack.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'suggestions,': 0.07; 'imply': 0.09; 'thread,': 0.09; 'timeout': 0.09; 'thread': 0.11; 'passed.': 0.16; 'query.': 0.16; 'subject:threads': 0.16; 'threads': 0.16; 'timeout,': 0.16; 'trying': 0.21; 'programming': 0.23; 'minutes.': 0.23; 'specified': 0.23; "i've": 0.23; 'seems': 0.23; 'header:User-Agent:1': 0.26; 'thanks!': 0.26; "doesn't": 0.28; 'actual': 0.28; 'servers.': 0.29; 'case,': 0.29; 'starts': 0.29; 'checks': 0.30; 'query': 0.30; 'code': 0.31; 'implement': 0.32; 'cancel': 0.33; 'like:': 0.33; 'to:addr:python-list': 0.33; 'know.': 0.33; 'languages': 0.33; 'another': 0.33; 'server': 0.35; 'so,': 0.35; 'expected': 0.35; 'sometimes': 0.35; 'something': 0.35; 'really': 0.36; 'but': 0.36; 'generation': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'turn': 0.36; 'hours.': 0.37; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'end': 0.40; 'content- disposition:inline': 0.60; 'within': 0.64; 'canceling': 0.84; 'killing': 0.84; 'outside.': 0.84; 'received:72.249': 0.84; 'received:83.103': 0.84
DomainKey-Signature a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=nerdshack.com; b=45fr+iNkBjHoDFE7eQTJ8fJkav35MjUWykiwJMPjeqReyQvxDPZV29qmywJ0B1uIWzOgOzWK0za8m3bTrnf+PVM6VWlLr6JbjRG3FpF1zeaPnFbmHAxJ7LoCXuvq+EEovrx+LJ5S4YyGtU+TB9dKVUi8i1vST/jDTGu6M26qtwc=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent;
Date Sat, 26 Jan 2013 15:14:08 +0200
From hyperboreean <hyperboreean@nerdshack.com>
To python-list@python.org
Subject Cancel threads after timeout
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.20 (2009-06-14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1073.1359207608.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359207608 news.xs4all.nl 6879 [2001:888:2000:d::a6]:49848
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37720

Show key headers only | View raw


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


Thread

Cancel threads after timeout hyperboreean <hyperboreean@nerdshack.com> - 2013-01-26 15:14 +0200

csiph-web