Question: I need to get the absolute path of a file in python, i already tried `os.path.abspath(filename)` in my code like this:

```py
def encrypt(filename):
   with open(filename, 'rb') as toencrypt:
      content = toencrypt.read()
      content = Fernet(key).encrypt(content)
   with open(filename, "wb") as toencrypt:
      toencrypt.write(content)

def checkfolder(folder):
   for file in os.listdir(folder):
      fullpath = os.path.abspath(file)
      if file != "decrypt.py" and file != "encrypt.py" and file != "key.txt" and not os.path.isdir(file):
         print(fullpath)
         encrypt(fullpath)
      elif os.path.isdir(file) and not file.startswith("."):
         checkfolder(fullpath)

```

the problem is that `os.path.abspath(filename)` doesn't really get the absolute path, it just attach the current working directory to the filename which in this case is completely useless. how can i do this?

Answer: 
If you want to control something over time in Pygame you have two options:

1. Use [`pygame.time.get_ticks()`](https://www.pygame.org/docs/ref/time.html#pygame.time.get_ticks) to measure time and and implement logic that controls the object depending on the time.
2. Use the timer event. Use [`pygame.time.set_timer()`](https://www.pygame.org/docs/ref/time.html#pygame.time.set_timer) to repeatedly create a [`USEREVENT`](https://www.pygame.org/docs/ref/event.html) in the event queue. Change object states when the event occurs.

For a timer event you need to define a unique user events id. The ids for the user events have to be between `pygame.USEREVENT` (24) and `pygame.NUMEVENTS` (32). In this case `pygame.USEREVENT+1` is the event id for the timer event.
Receive the event in the event loop:

```py
def spawn_ship():
    # [...]

def main():
    spawn_ship_interval = 5000 # 5 seconds
    spawn_ship_event_id = pygame.USEREVENT + 1 # 1 is just as an example
    pygame.time.set_timer(spawn_ship_event_id, spawn_ship_interval)

    run = True
    while run:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

             elif event.type == spawn_ship_event_id:
                 spawn_ship()

```

Also see [Spawning multiple instances of the same object concurrently in python](https://stackoverflow.com/questions/62112754/spawning-multiple-instances-of-the-same-object-concurrently-in-python/62112894#62112894) and [How to run multiple while loops at a time in Pygame](https://stackoverflow.com/questions/65263318/how-to-run-multiple-while-loops-at-a-time-in-pygame/65263396#65263396).
You could try making spawn\_ship async, then use a thread so it doesn't affect the main loop

```py
import threading

def main():
   threading.Timer(5.0, spawn_ship).start()

async def spawn_ship():
   # ...

```