threading : make stop the caller
Laurent Claessens
moky.math at gmail.com
Sun Jun 19 11:39:02 EDT 2011
Le 19/06/2011 17:19, Chris Angelico a écrit :
> On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessens<moky.math at gmail.com> wrote:
>> Hello
>>
>>
>> I've a list of tasks to perform. Each of them is a threading.Thread.
>> Basically I have :
>>
>> while task_list :
>> task = task_list[0]
>> task.run()
>> task_list.remove(task)
>
> I'm not understanding what you're doing with threads here. Are you
> using threading.Thread but then calling its run() method
> synchronously?
Woops yes. I missprinted my example. I was using task.start() of course.
The aim is to copy the content of a repertory (with some conditions on
each file, so I cannot use shutils or something).
I've one thread that runs over the repertory and fill the list
'task_list' with taskes from the following class :
class FileCopyTask(threading.Thread):
def __init__(self,source,destination,old_version):
threading.Thread.__init__(self)
self.source = source
self.destination = destination
def run(self):
try :
shutil.copy(self.source,self.destination)
except (IOError,OSError),data :
<WHAT TO PUT HERE ??>
else :
print "file copied"
In the same time I've a thread that read the list and perform the
operations:
def run():
while task_list :
task = task_list[0]
task_list.remove(task)
task.start()
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.
thanks for any help
Laurent
More information about the Python-list
mailing list