I have a while loop that fetches data from a mysql table and in each iteration it does many different things using many functions and classes.

The problem is that sometimes it gets stuck (maybe trying to open or read a file), so is there any way to skip the current iteration if it gets stuck by setting a timeout?

Can I set a timeout for a while loop so that if at any iteration that timeout limit is reached it'd continue to the next iteration?