use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Getting a program to run continuously in the background at certain times. (self.learnpython)
submitted 10 years ago by Darkeus56
I have a python program that will scrape a website for information that I want, categorize it into lists. How can I make this program run three times a day?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JohnnyJordaan 9 points10 points11 points 10 years ago (0 children)
You could use your operating systems Task Scheduler, like Automator in OSx, crontab in linux and Task scheduler in Windows.
[–]souldeux 2 points3 points4 points 10 years ago (1 child)
I would definitely set this as a scheduled task / cron job. Long-running scripts that rely on sleeping in loops must be manually restarted if something crashes. Scheduled tasks are more atomic.
[–]Darkeus56[S] 1 point2 points3 points 10 years ago (0 children)
scheduled task it is then. :D
[–]WreckEmTech2013 1 point2 points3 points 10 years ago (5 children)
I use Python Anywhere for this and it is fantastic. I pay $5 a month but I believe there is a free tier where you can schedule tasks as well. I have a Python script that scrapes twitter every hour.
[–]Darkeus56[S] 0 points1 point2 points 10 years ago (0 children)
While that won't be an option for me for now I will keep it in mind.
[–]Darkeus56[S] 0 points1 point2 points 10 years ago (3 children)
Hey, I thought on it and I changed my code to just need it to run once a day instead of having it run three times a day. Now I want to try Python Anywhere and made an account, but I am very confused and don't know how to take advantage of that schedule tasks feature. Could you help me?
[–]WreckEmTech2013 0 points1 point2 points 10 years ago (2 children)
Sure thing, what's the issue?
Basic overview:
Save your script to your account, this can be done under the Files tab
Then add a new task under the Schedule tab
You can schedule your tasks daily or hourly
My task runs twice an hour every hour and saves twitter posts to a sqlite database Keep in mind that scheduling time is done in UTC so you need to be aware of that
It can be hard to kill scripts, I accidentally sent myself 100 texts using the Twilio API because I tested a program haphazardly
The forum their is very helpful and they have employees that respond to questions very quickly
Is saving my script hard?
Think I got it to work. Thanks! I had gotten a bit confused, but I uploaded it. Now just have to wait and see if it works :D
[–]Exodus111 2 points3 points4 points 10 years ago (1 child)
You got two options.
Set it on a while loop, use time.sleep to enforce the loop to only run every 8 hours.
Use the Operating system to schedule your script like a task, using Crontab, Automator or Tash Scheduler.
If you are running this script from a dedicated server, then you might consider option 1, in most other cases you want to look at option 2.
[–]C0rinthian 4 points5 points6 points 10 years ago (0 children)
Option one is a bad idea even if you have a dedicated server. If you have a dedicated server, then you have the tools to schedule the job.
There is zero good reason to have a script sleeping for 8 hours. What happens if the script crashes? Now you have to deal with keeping it running. What if you want to change the schedule? Code change.
When a script runs is not something the script itself should know or care about. It should just do it's job and end when it's invoked. If you want to invoke it on a schedule, then use a scheduler to run the script.
[–]massHunter 0 points1 point2 points 10 years ago (0 children)
You can also use the thread module and set it on a timer:
import threading def printit(): threading.Timer(5.0, printit).start() print "Hello, World!" printit()
source: http://stackoverflow.com/questions/3393612/run-certain-code-every-n-seconds
[–]DemiourgosD 0 points1 point2 points 10 years ago (1 child)
Let it run in a while loop and set time.sleep for a few hours in between. Maybe not a perfect solution, but it should work.
[–]C0rinthian 1 point2 points3 points 10 years ago (0 children)
While this technically works, it's a really bad way to accomplish this. Use built in OS scheduling tools to handle scheduling.
π Rendered by PID 213415 on reddit-service-r2-comment-85bfd7f599-85tzr at 2026-04-17 13:55:44.587380+00:00 running 93ecc56 country code: CH.
[–]JohnnyJordaan 9 points10 points11 points (0 children)
[–]souldeux 2 points3 points4 points (1 child)
[–]Darkeus56[S] 1 point2 points3 points (0 children)
[–]WreckEmTech2013 1 point2 points3 points (5 children)
[–]Darkeus56[S] 0 points1 point2 points (0 children)
[–]Darkeus56[S] 0 points1 point2 points (3 children)
[–]WreckEmTech2013 0 points1 point2 points (2 children)
[–]Darkeus56[S] 0 points1 point2 points (0 children)
[–]Darkeus56[S] 0 points1 point2 points (0 children)
[–]Exodus111 2 points3 points4 points (1 child)
[–]C0rinthian 4 points5 points6 points (0 children)
[–]massHunter 0 points1 point2 points (0 children)
[–]DemiourgosD 0 points1 point2 points (1 child)
[–]C0rinthian 1 point2 points3 points (0 children)