threading : make stop the caller

Laurent Claessens moky.math at gmail.com
Sun Jun 19 12:08:23 EDT 2011


Le 19/06/2011 18:03, Chris Angelico a écrit :
> On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens<moky.math at gmail.com>  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



More information about the Python-list mailing list