threading : make stop the caller

Chris Angelico rosuav at gmail.com
Sun Jun 19 11:19:34 EDT 2011


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?

Normally threads are used for asynchronous operations. You would then
use the start() method to spin the thread off; it will return almost
immediately, and the thread will run to completion in parallel with
you. But then you can't halt the main loop, because it will have
already finished by the time you detect the IOError (starting a bunch
of threads is pretty quick). On the other hand, the code you're
showing seems to simply call each thread's run() method one by one,
which should propagate any exceptions in the same way that function
calls usually do.

Can you share the code for one of the tasks, and show what happens
when it raises an exception?

Chris Angelico



More information about the Python-list mailing list