I'm using time.sleep() on a crypto price checking app I made. But i can only get it to run for a couple hours then the device I run it on will sleep. How do you get something to just run your script for hours/days/weeks?
I've ran this program on my computer, a raspberry pi, and an old android phone and the best I can get is the phone will run the program from 9pm to 5am on a good day.
I've tried turning off all sleep timers and all and I'd really rather not keep my PC on constantly but I'd love some help finding a solution none the less.
On a Windows machine, you can go to Task Scheduler and create running your script as a task at a particular time.
https://www.thewindowsclub.com/wake-up-computer-from-sleep-windows
Related
I'm working on a Windows application that will show time when my system was started. I tried to do something with WMI, I took SystemUpTime, but it gave me time since last startup. I am looking for first startup per day, so for example if user will turn on computer at 7:00 and later will do restart at 9:00 it should still show 7:00. Is there any library which can be helpful?
I'm not aware of a library that would do this.
One option would be to:
Make your program run on startup.
Save the boot time each time your program runs
Display the earliest boot time for the current day.
Save the boot times in sqlite3, its built in to Python these days.
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
I'm currently working on SiriProxy with my raspberry Pi, and I'm making a scheduled lighting system to siri so that I can give a command like this "Siri turn on my Bedroom light at 6pm". I dont know how to use cronjob as my scheduler.
If it's a one time job, you need at instead of cron. See linux at man page.
I'm fairly competent with Python but I've never 'uploaded code' to a server before and have it run automatically.
I'm working on a project that would require some code to be running 24/7. At certain points of the day, if a criteria is met, a process is started. For example: a database may contain records of what time each user wants to receive a daily newsletter (for some subjective reason) - the code would at the right time of day send the newsletter to the correct person. But of course, all of this is running out on a Cloud server.
Any help would be appreciated - even correcting my entire formulation of the problem! If you know how to do this in any other language - please reply with your solutions!
Thanks!
Here are two approaches to this problem, both of which require shell access to the cloud server.
Write the program to handle the scheduling itself. For example, sleep and wake up every few miliseconds to perform the necessary checks. You would then transfer this file to the server using a tool like scp, login, and start it in the background using something like python myscript.py &.
Write the program to do a single run only, and use the scheduling tool cron to start it up every minute of the day.
Took a few days but I finally got a way to work this out. The most practical way to get this working is to use a VPS that runs the script. The confusing part of my code was that each user would activate the script at a different time for themselves. To do this, say at midnight, the VPS runs the python script (using scheduled tasking or something similar) and runs the script. the script would then pull times from a database and process the code at those times outlined.
Thanks for your time anyways!
I'm turning my raspberry pi running on raspbmc (based on Debian) into an alarm clock that turns my tv on, displays the weather and plays a predifined song at, you guessed it, a specific time. I currently have most of the functionality implemented with Python e.g.: storing the path to a file for the song and filling in the wake-up time via a simple web interface.
I'm wondering what the best way (least intensive) is to run the wake-up routine at a specific time entered by me and, of course, change it when a new time is entered.
Hope you guys can help me out. Thanks!
Just set up a cron task and set up a python script to perform the actions you need when triggered by cron.
Try:
% crontab -e
add a line:
10 7 * * 1-5 /path/to/your/script
Save & exit.
This should run your script at 7:10 Monday-Friday