Create a python routine that runs a script every 30 min

Asked

Viewed 1,188 times

-1

I created a code that copies a file from one folder and moves to another, but I have files every 30 min and I need this script to run at that time too.

  • Linux or Windows? Ever heard of scheduled tasks?

  • Task Manager on Windows and Cron on Unix systems.

1 answer

1

if you want to do this internally by code, you can use the library time:

import time

while True:

    print('funcionou')

    time.sleep(1800)

At each n seconds (1800 segundos é o equivalente a 30 minutos), the code within the scope of while will be executed whenever you arrive at the designated time. For this, you will have a specific terminal window for it to carry out this process, and to end the flow you can use a KeyboardInterrupt.

Also, you have the possibility to use a task schedule or a automator to execute the arquivo.py without the need to let it run dormant through the Sleep.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.