Message from discussion How to interrupt a task which is running in a thread?
Received: by 10.224.183.13 with SMTP id ce13mr303054qab.4.1348655865086;
Wed, 26 Sep 2012 03:37:45 -0700 (PDT)
Received: by 10.236.150.16 with SMTP id y16mr14917yhj.8.1348655864032; Wed, 26
Sep 2012 03:37:44 -0700 (PDT)
Date: Wed, 26 Sep 2012 03:37:43 -0700 (PDT)
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=22.214.171.124;
Subject: Re: How to interrupt a task which is running in a thread?
From: Arjen Markus <arjen.markus...@gmail.com>
Injection-Date: Wed, 26 Sep 2012 10:37:45 +0000
Content-Type: text/plain; charset=ISO-8859-1
On Wednesday, September 26, 2012 11:56:27 AM UTC+2, Andy wrote:
> Hi Arjen
> Thanks for your reply.
> I have a Tk GUI app. There are "Start" and "Stop" buttons on my GUI. Afte=
r pressing "Start" button, my app will execute a command in a thread, maybe=
copy a large file. It will take a long time. At the moment, I want to pres=
s "Stop" button to stop this action immidiately. And then, I can press "Sta=
rt" button to copy that file again. This is what I want. Do you have any id=
ea? Or is there another way to achieve this?
There is no general way in which you can achieve that, as far as I know.=20
The only thing I can think of is that the task itself cooperates with you.
That is, if you take the copying example:
Some procedure copies chunks and looks regularly if it should continue.
If it sees it should interrupt the work, it saves whatever state needs savi=
and returns control.
One possible mechanism to make this easier is the use of coroutines, but ev=
they require cooperation.
Perhaps http://wiki.tcl.tk/1526 holds some ideas you can use.