Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.le-studio75.com!news.univ-fcomte.fr!not-for-mail From: Laurent Claessens Newsgroups: comp.lang.python Subject: Re: threading : make stop the caller Date: Sun, 19 Jun 2011 18:08:23 +0200 Organization: A poorly-installed InterNetNews site Lines: 19 Message-ID: <4DFE1EF7.10909@gmail.com> References: NNTP-Posting-Host: soleil.univ-fcomte.fr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.univ-fcomte.fr 1308499697 11351 194.57.84.1 (19 Jun 2011 16:08:17 GMT) X-Complaints-To: news@news.univ-fcomte.fr NNTP-Posting-Date: Sun, 19 Jun 2011 16:08:17 +0000 (UTC) Cc: python-list@python.org To: Chris Angelico User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7978 Le 19/06/2011 18:03, Chris Angelico a écrit : > On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens wrote: >> My problem is that when FileToCopyTask raises an error, the program does not >> stop. >> In fact when the error is Disk Full, I want to stop the whole program >> because I know that the next task will fail too. > > If you're starting a thread for every file you're copying, you're > starting a huge number of threads that probably will just end up > fighting over the disk. To get a reasonably efficient early-abort, I'd > recommend having a fixed pool of worker threads (say, ten of them), > and have each thread (a) check if the early-abort flag is set, and > then (b) start copying the next file in queue. Once the queue's empty > or the early-abort flag is set, all ten threads will terminate when > they finish their current transfers. Yes, my example was simplified, but I do that :) Laurent