Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import time
- class PageForAMinute:
- _instance = None
- _lock = threading.Lock()
- def __new__(cls):
- with cls._lock:
- if not cls._instance:
- cls._instance = super().__new__(cls)
- return cls._instance
- def __init__(self):
- self.in_process = False
- def run_my_code(self):
- if self.in_process:
- return
- self.in_process = True
- triggered_last = time.time()
- def loop_logic():
- while True:
- # Perform your partial sync and write operations here
- # Check if a minute has passed since the last trigger
- if time.time() - triggered_last >= 60:
- break
- # Sleep for a short interval before checking again
- time.sleep(0.1)
- self.in_process = False
- threading.Thread(target=loop_logic).start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement