Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3690694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:03:51+00:00 2026-05-19T04:03:51+00:00

I was curious how you can run a python script in the background, repeating

  • 0

I was curious how you can run a python script in the background, repeating a task every 60 seconds. I know you can put something in the background using &, is that effeictive for this case?

I was thinking of doing a loop, having it wait 60s and loading it again, but something feels off about that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:03:51+00:00Added an answer on May 19, 2026 at 4:03 am

    I think your idea is pretty much exactly what you want. For example:

    import time
    
    def do_something():
        with open("/tmp/current_time.txt", "w") as f:
            f.write("The time is now " + time.ctime())
    
    def run():
        while True:
            time.sleep(60)
            do_something()
    
    if __name__ == "__main__":
        run()
    

    The call to time.sleep(60) will put your program to sleep for 60 seconds. When that time is up, the OS will wake up your program and run the do_something() function, then put it back to sleep. While your program is sleeping, it is doing nothing very efficiently. This is a general pattern for writing background services.

    To actually run this from the command line, you can use &:

    $ python background_test.py &
    

    When doing this, any output from the script will go to the same terminal as the one you started it from. You can redirect output to avoid this:

    $ python background_test.py >stdout.txt 2>stderr.txt &
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this would violate convention, but I'm curious to know if you can
I've always been curious to see if I can show, hide or change a
Curious to know how people set up their personal and/or work development environment, in
I have a small project I am doing in Python using web.py. It's a
In the process of trying to write a Python script that uses PIL today,
curious if anyone might have some insight in how I would do the following
Curious to get people's thoughts. I conduct frequent interviews, and have had enough in
Curious as to 99.95% uptime REALLY means; Is it really going to go down
I curious to how different people solve integration of systems. I have a feeling
Im curious what the exact meaning of committed memory is when the value is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.