Janish has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks

Pls help me on this. I have a few of jobs whereby each of them will be triggered in sequential manner when a "RunAll" button is clicked. How do I set another "KillAll" button to kill all the invoked jobs in case I want to abort all the rest of jobs halfway?

Below is how I invoked my jobs (note: I'm using Tk::ExecuteCommand in my script). Each job is triggered successfully one after another but it only kill job1 in below code for sub KillAll

Code for "RunAll" button:-

sub RunAll{ $run_job1_bttn->invoke(); $run_job2_bttn->invoke(); $run_job3_bttn->invoke(); }

Code for "KillAll" button:-

sub KillAll { my $msg = $mw->Dialog( -title => "Warning", -buttons => [ "Yes", "Cancel" ], ); $msg->add("Label", -text => "Sure to kill all jobs?", -wraplength => '300', )->pack(); my $killbutton = $msg->Show; if ($killbutton eq "Yes") { $ec_job1->kill_command; $ec_job2->kill_command; $ec_job3->kill_command;#each $ec_job is execute_command callin +g an external script. } }

Pls suggest a method so that I can kill all running jobs successfully without abort the window. Thank you!

Replies are listed 'Best First'.
Re: Kill a serial of jobs with a button click in Perl/TK
by GotToBTru (Prior) on May 22, 2015 at 16:30 UTC

    Docs for Tk::ExecuteCommand suggest the kill_command is a method of the same object that execute_command. We can't see the connection (if any) between $run_job1_bttn and $ec_job1, for instance. We need more to work with, if you want more specific help.

    Dum Spiro Spero

      Every run job button IE: $run_job1_bttn will trigger a subroutine to execute a child script. The subroutine RunAll works just fine as it is able to trigger each jobs running sequentially but the problem is on the KillAll subroutine, it seem fail to kill all jobs (triggered by the RunAll sub) but only manage to kill the first one.

        kill, AFAIK, only works on running processes. If they are executing sequentially, only one of them is "running", the rest is ... waiting? queued? (what I want to say is: they probably are not "processes" yet)

        So you have to remove them from the queue (or whatever), preferrably before killing the first, in order to avoid race conditions.

Re: Kill a serial of jobs with a button click in Perl/TK
by Anonymous Monk on May 22, 2015 at 10:37 UTC
    So whats the problem?