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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill/Stop a sub from another sub?

Status
Not open for further replies.

xhonzi

Programmer
Jul 29, 2003
196
US
So,
Does perl have any commands that allow you to forcefully stop a subroutine? I know I can stop it from within using exit, but it would be easier if I could stop it from without.

Something like:
substop("SubName");

would be awesome.

xhonzi
 
You could try using an alarm if the problem is it takes too long. See the alarm() function documentation.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
xhonzi,

Unless you're dealing with threads or forked processing, your question doesn't make any sense. Most perl programs are sequential, as in only one sub has active control at any given time. Can you clarify the context in which you are asking the question?

- Miller
 
Perl Tk. It's possible to push a button and start a subroutine while another is going if one has used $mw->update in the first.

Part of my program searches for files. As it finds them, it adds them to a list and performs $mw->update; As the list is populating, a user can click on the file and get more information on it in the same window. (The text box is cleared first with a delete(1.0,'end') However, right after the information is displayed, more search results appear below as the search continues. If enough results appear, the information is lost as the window scrolls.

I know I could disallow the user to click until after the search finishes, but since the search finds most recent files first, I think the user would be waiting a long time for the search to find files he/she doesn't care about.

xhonzi
 
Even with Tk, Perl is still executed sequentially. When the code for your button executes, Perl is only running that code, which is why the rest of the GUI will freeze unless you keep running $mw->update.

So a logical way to look at it is...

1. The code for the button is running.
2. You should be able to stop it from running via the GUI.
3. The GUI is only open to receive events when you call update()

So you could do something like, say, have $cancel be a variable and each time you call update in the sub:

Code:
$mw->update;
return if $cancel;

And then another button can just set $cancel = 1

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top