简体   繁体   中英

How to run a python script constantly on Windows 10 best practice?

I'm trying to run a script on windows 10 machine that I set a server in my LAN. I would like for the script to restart 30 seconds after it finished, forever. Is there any better way then putting it in an infinite while loop?

Here is my code:

import Time 
while True:
     print("Here does all the things it's supposed to")
     # Does something
     time.wait(30)

While this works, I'm worried that it will affect performance and maybe memory of of the server or slowing it down in time.

Is there any better way to run a code forever in a loop in windows, perhaps with some command for terminal or any other option better then mine? Kindly note the machine is a windows 10, 64 Bit arch, not a linux machine.

You can look up a term more famously known as a "chron job" Heres an article I found out which can help: https://www.technipages.com/scheduled-task-windows

using "chron" you can schedule when to run a script at exact date and time. Or choose how to run code in infinite loop. You can also decide when to stop the script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM