Option 1. Magma's Alarm(s) function (described here).
This will quit Magma after s seconds. So, if you are fine with closing Magma completely, you could insert Alarm(15 * 60); at the appropriate location.
Option 2. For whatever reason, you may not want to completely quit Magma and maybe move on to the next lines. This seems equivalent to wanting to cancel a command midway, i.e., pressing Ctrl-C. However, note that this may not immediately terminate the command, as Magma tries to tries to interrupt at a "convenient point" (source).
Here is one outline how you can simulate the Ctrl-C, using Sage: Note that Sage has a Magma interface (more details here).
Sage also has an "alarm" function that can time certain processes. (Maybe you can Google this and find a more canonical reference, but here is what I have.)
An example of how you could now use it is as follows:
Suppose your Magma code is
A := 1;
DoSomethingDifficult(A);
DoEasyThings(A);
You would convert it to the following Sage code:
magma.eval("A := 1;")
alarm(15 * 60)
try:
magma.eval("DoSomethingDifficult(A);")
except KeyboardInterrupt:
print("Did not work! :(")
cancel_alarm()
magma.eval("DoEasyThings(A);")
Note: This seems like a quite hack-y workaround, and I don't know the internal workings well enough to assure that "nothing weird will go wrong".