Oscar Wang commited on
Commit
bd98967
·
verified ·
1 Parent(s): 755e048

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -19,7 +19,6 @@ state = {
19
  }
20
 
21
  state_lock = Lock()
22
- stop_threads = False
23
 
24
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
25
  def get_token_count(client):
@@ -27,7 +26,7 @@ def get_token_count(client):
27
  return int(result)
28
 
29
  def monitor_growth():
30
- while not stop_threads:
31
  try:
32
  curr_count1 = get_token_count(client1)
33
  curr_count2 = get_token_count(client2)
@@ -63,19 +62,21 @@ token_count_placeholder = st.empty()
63
  growth_speed_placeholder = st.empty()
64
 
65
  def update_ui():
66
- while not stop_threads:
67
  with state_lock:
68
  token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
69
  growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
70
  time.sleep(1)
 
71
 
 
72
  update_thread = Thread(target=update_ui, daemon=True)
73
  update_thread.start()
74
 
 
75
  try:
76
  while True:
77
  time.sleep(1)
78
  except KeyboardInterrupt:
79
- stop_threads = True
80
  monitor_thread.join()
81
  update_thread.join()
 
19
  }
20
 
21
  state_lock = Lock()
 
22
 
23
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2), retry=retry_if_exception_type(httpx.ReadTimeout))
24
  def get_token_count(client):
 
26
  return int(result)
27
 
28
  def monitor_growth():
29
+ while True:
30
  try:
31
  curr_count1 = get_token_count(client1)
32
  curr_count2 = get_token_count(client2)
 
62
  growth_speed_placeholder = st.empty()
63
 
64
  def update_ui():
65
+ while True:
66
  with state_lock:
67
  token_count_placeholder.metric("Total Token Count", state["prev_total_tokens"])
68
  growth_speed_placeholder.metric("Total Growth Speed", state["total_growth_speed"])
69
  time.sleep(1)
70
+ st.experimental_rerun()
71
 
72
+ # Start the update UI thread
73
  update_thread = Thread(target=update_ui, daemon=True)
74
  update_thread.start()
75
 
76
+ # Keep the app running
77
  try:
78
  while True:
79
  time.sleep(1)
80
  except KeyboardInterrupt:
 
81
  monitor_thread.join()
82
  update_thread.join()