You have essentially two solutions. One solution might be to use a separate thread to print out the value of the dictionary. This solution would probably be the most similar to your attempted solution using the Timer. For example:
import threading
import time
class MonitoringThread(threading.Thread):
def __init__(self, interval, dict):
super(MonitoringThread, self).__init__()
self._continue = True
self._interval = interval
self._dict = dict
def stop(self):
self._continue = False
def run(self):
while self._continue:
print self._dict
time.sleep(self._interval)
def main():
data_dict = {'test': 0}
t = MonitoringThread(10, data_dict)
t.start()
try:
while True:
time.sleep(1)
data_dict['test'] += 1 # Example update
except:
t.stop()
if __name__ == '__main__':
main()
Alternatively, you could also try structuring your code so that it updates the dictionary in a loop, but only checks once 10 seconds has passed:
import time
def main():
data_dict = {'test': 0}
prev_time = time.time()
while True:
time.sleep(1)
data_dict['test'] += 1
if time.time() - prev_time >= 10:
print data_dict
prev_time = time.time()
if __name__ == '__main__':
main()