How to make an action happen every minute in Python
count, loops, python, time
Solution
You need to import the thread module and the itertools (in addition to svks' comment) in python
import thread, time, itertools
initialize your threadsafe counter like
wood = itertools.count().next()
and write your counter update into a function
def updateCounter():
while True:
wood.next()
# wood += 1
time.sleep(60)
and kick off a new thread with
thread.start_new_thread(updateCounter, ())
But the ressource variables like wood must be accessable from within the counter function!
Problem
I would like to add 1 to a variable every minute without interfering with the code that's already running. It is a game so I want in the background for wood+1, rock+1, fish+1 to happen every minute without the user knowing. the time.sleep won't work in this situation because it pauses the whole program. ``` start=time.time() #some code end=time.time() if end-start > 60: wood = wood+1 rock = rock+1 ``` I tried doing something above but could not get it to continuously count. It only measures how long it takes for #some code to be executed. Any help would be great! Thanks in advance.