Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to stop a running Tcl procedure

Status
Not open for further replies.

richwd

Programmer
Oct 12, 2011
17
US
Let's say I have a Tk GUI app that's running a procedure that takes a long time. Let's also say that I've changed my mind and don't want to wait until this procedure ends. I'd like to have a "Stop" button on my GUI that would accomplish this. Is that possible? I already have a button that quits the whole program but I'd like the program to keep running and window still be visible so I can click another button to do something else. Is there any way to stop the current running procedure? It's not multi-threading.
 
Hi,
Please examine the following, this is just one way of doing it, I am sure there are more sophisticated methods but this is what I can think of as a quick and dirty method:

Code:
proc proc1 {} {
  while {$::exitproc1} {
    puts "processing proc1"
    after 200
    update
  }
}

proc proc2 {} {
  while {$::exitproc2} {
    puts "processing proc2"
    after 200
    update
  }
}

pack [button .b1 -text proc1 -command {set ::exitproc1 1; set ::exitproc2 0; proc1}]
pack [button .b2 -text proc2 -command {set ::exitproc2 1; set ::exitproc1 0; proc2}]

But, ofcourse, this to work, demands that whatever you do in the while-loop does not occupy the processor for too long with each iteration.
 
Thanks,

I did something similar with a boolean variable and having the procedure check it like you did but you can't break out of it until you get to a point where you can check the variable right? Instead of doing a "puts" it may be a procedure processing lots of files in a directory and I don't want to wait till it's done to get to the point where you can check the variable. How can you return immediately in the middle of a procedure instead of when it's done? Something like killing a process id. Are there procedure ids? Addresses?

I was wondering if there was something like &address_of_proc.return if you get what I mean. So you can have the function issue a return wherever it's at the current moment. Don't functions (procedures) have addresses?
 
What you want is an asynchronious interrupt of a process.

Maybe, using 'trace' could help you out in your quest. You might want to examine this page for more info :

Trial & error I would say...

If you got the time and patience, have also a look in

I am out of ideas, hope it helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top