How to continue after one timeout action aborts that macro

I have two macros. 1 is parent and 2nd is child macro.
So I have set up "child" macro with some action which is having abort timeout action. And it is now aborting whole the parent and child macros as soon as that timeout action triggers.
But I want to keep the "parent" macro running even after "child" macro aborts. How can I achieve that?

Did you try disabling the abort checkbox and only setting up the timeout in the child macro?

tried it for you, not the way to solve it

1 Like

I would suggest something like this. In the Child Macro your Action is still set to timeout but is not set to Abort the Macro. You then follow that with an If Then Action which keeps the Macro going if the first Action didn't timeout and Cancels just the Child Macro if the timeout was exceeded. (The first Action about the J key being down is just a placeholder for an Action as I don't know what Action is set to timeout in your Macro.)
EXAMPLE Cancel just this Macro if timeout exceeded.kmmacros (3.3 KB)

Click to Show Image of Macro

2 Likes

yes that is why I had asked here. Tried that already. It looks like bug or something.

I want to set it up like it the "Set action time out " option should stop the child macro only. then the parent macro should keep on running the further steps in it.

It's not a bug, after the timeout of the action you should test on a condition as Zabobon suggested.

Yes, what I have uploaded should do that. I've modified it since I first posted to test whether the first Action timeouts or not. If the Action timeouts just the Child Macro will be cancelled. If the Action is completed before timeout the Child Macro will keep running. In both cases the Parent Macro will pause while the Child Macro runs and resume running when the Child Macro either completes or timeouts.

You could put in your own coping mechanism instead of trying to handle the aborts. If you put the problem section of the child macro in a "Try/Catch" block you can handle the error yourself, either letting the macro complete (and thus return control to the parent) or complete and return an appropriate result (if the parent needs some info back from the child) -- you then handle the error case in the parent.

But how best to do this will depend on the relationship between the macros -- it'll help if you post them.

Kindly see this attached macro.
You can see the parent macro in it, which is repeating 5 times of the child macro. I need it like as soon as timeout exceeded, it should completely skip that "5 times repeat action" and pop up that problem solved message.
Experiments Macros.kmmacros (31.3 KB)

At the moment you have your Timeout in the Child Macro and you are calling the Child Macro 5 times from the Parent Macro so, it will always run 5 times whatever.

I think what you want instead, is for the whole subroutine to Timeout within a certain total time, no matter how many times it has looped?

So, I would suggest either put a 5 x loop (using a Repeat Action) in the Child Macro itself (and just call it once from the Parent Macro) or do similar to what @Nige_S is suggesting and do the whole thing in one Macro.

Here is an example of that second approach (using one Macro rather than two)

Notes -
The Timeout of 3 seconds is set in the Repeat Action. It is set to Timeout but not to Abort the Macro. So, the rest of the Macro will carry on after the Timeout.

image

The Magenta Action is a Placeholder for whatever task you are attempting. For this Example Macro it has been set to something that will never work and will pause forever, so the enclosing Repeat Action will always timeout. The Magenta Action has no Timeout settings itself.

EXAMPLE Cancel Loop if timeout exceeded.kmmacros (5.3 KB)

Click to Show Image of Macro

If you really want to do this with two Macros, I suppose the Child Macro would look a bit like the below (and just be called once from the Parent Macro). Again the Timeout is set in the Repeat Action only.

EXAMPLE Child Macro with 5 x loop.kmmacros (3.8 KB)

Click to Show Image of Macro

I have multiple child macros, which needs to be run in sequence one after another. In the above solution, it is canceling this child macro but after that other child macros aren't running since this one is cancelled. How can I solve that problem?

No. The above solutions only cancel a single Child Macro (which was your original question).

It would only cancel other Child Macros if they were being called by itself. Assuming the other Child Macros are called by the parent Macro and the Parent Macro is not cancelled only a single Child Macro will be cancelled.

I think what makes this confusing is that the default behaviour of an Action timing out is to Cancel the whole Macro run including all other Macros in that run (for reasons of safety). To Cancel just a single Child Macro if it timeouts means carefully checking the Action timeout settings in that Child Macro to make sure it is not cancelling if it timeouts. And then following that with a condition that cancels just itself:

But using the Cancel Macro mechanism to deal with what are probably control flow decisions seems a bit overkill to me.

Your original question mentioned just two Macros - a Parent and a Child. And then you mentioned a Parent that ran a single Child Macro 5 times. Now you are talking about running multiple Child Macros. It is all possible using the solutions above, but as the situation becomes more complex it is more likely you are going to make an error and debugging becomes harder (especially as the Acton timeout settings are hidden behind the gear menu).

If you can't get it to work, you might want to try @Nige_S's suggestion as that looks like it might be more transparent.

Should you solve this problem?

If the child macros "need to be run in sequence, one after the other" that implies that each is dependent on the actions of the previous -- surely they should all be stopped if a previous child fails for some reason. Otherwise you need to be sure that subsequent macros are "safe" to run, regardless of how/why the previous one failed.

This kind of control problem can get tricky. The first step, IMO, is write down what you want to happen, the order in which it should happen, and the inputs/outputs for each step so you can check what can be allowed to continue on a failure and what must cause a complete stop. Flow charts are fun :wink:

Once you've got that nailed down we might be able to give more specific advice...

1 Like

And just one other thought, assuming you have broken the task down to several small tests or steps and you want each step to be tried and if it timeouts go onto the next step. That is what a standard timeout (without any cancelling of Macros) can do.

The example Macro that you uploaded earlier had a Child Macro that tried something and was set to timeout. It didn't need a Cancel Macro Action at all, as after the timeout it would have returned to the next step in the Parent Macro anyway.

You see I have like a grand parent macro also. which consists of multiple parents and parent macros consists of multiple child macros.

Yes, I thought you might have🤣

You have a few options when a task in a Macro timeouts:

  1. timeout and cancel the whole Macro run
  2. timeout and cancel just this one Child Macro in the run (as shown above)
  3. timeout and not cancel anything - continuing to the next step in the Macro (which might be calling another Macro).

So, if these Child Macros are called one after the other from a Parent Macro, Option 2 should work.
If they are called by the Child Macros themselves then, Option 3 should work.

There are always lots of options and possible solutions.

Exactly why @Nige_S said: