When you set multiple termination parameters, Gurobi Optimizer will stop when it reaches the first one. For example, if you want to stop if you get to a 10% MIP gap or if 60 seconds have elapsed, then set MIPGap=0.1 and TimeLimit=60.
If you want a more complex set of stopping criteria, you will need to use warm starts. For example, suppose you need a 1% MIP gap, but you would prefer a smaller MIP gap if it takes less than 300 seconds. In this case, start with TimeLimit=300. If the value of the MIPGap attribute is greater than 0.01 when the time limit is reached, then increase the TimeLimit parameter, set the MIPGap parameter to 0.01, and continue to solve the MIP.
If you want to set a time limit that is considered only if a feasible solution is found, the code could look something like:
timeLimit = 20
m = read('b1c1s1.mps.gz')
oldSolutionLimit = m.Params.SolutionLimit
m.Params.SolutionLimit = 1
m.Params.TimeLimit = timeLimit - m.getAttr(GRB.Attr.Runtime)
m.Params.SolutionLimit = oldSolutionLimit - m.Params.SolutionLimit
except (GurobiError, AttributeError, Exception) as e:
print('Caught: ' + e.message)