I'm making a basic pygame where you need to shoot some ships that are spawning every few seconds, so here is the problem : I have a function that spawns my ship at a random x and y position. How do I make this function timeout every 4 seconds so that it doesn't spawn the ships too quickly but while also not interrupting the main game loop.
E.G :
def spawn_ship():
# functions that spawn the ship
# How do I make this run once every 5 seconds while not interrupting the main game loop
def main():
while True:
spawn_ship()