Advertisement
bitwise_gamgee

Untitled

May 30th, 2023
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import threading
  2. import time
  3.  
  4. class PageForAMinute:
  5.     _instance = None
  6.     _lock = threading.Lock()
  7.  
  8.     def __new__(cls):
  9.         with cls._lock:
  10.             if not cls._instance:
  11.                 cls._instance = super().__new__(cls)
  12.         return cls._instance
  13.  
  14.     def __init__(self):
  15.         self.in_process = False
  16.  
  17.     def run_my_code(self):
  18.         if self.in_process:
  19.             return
  20.  
  21.         self.in_process = True
  22.         triggered_last = time.time()
  23.  
  24.         def loop_logic():
  25.             while True:
  26.                 # Perform your partial sync and write operations here
  27.  
  28.                 # Check if a minute has passed since the last trigger
  29.                 if time.time() - triggered_last >= 60:
  30.                     break
  31.  
  32.                 # Sleep for a short interval before checking again
  33.                 time.sleep(0.1)
  34.  
  35.             self.in_process = False
  36.  
  37.         threading.Thread(target=loop_logic).start()
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement