r.go commited on
Commit
aaba8b5
·
1 Parent(s): 8d258cf
Files changed (1) hide show
  1. main.py +19 -2
main.py CHANGED
@@ -19,6 +19,7 @@ import queue
19
  from threads_util.main import Threads
20
  import asyncpraw
21
  import instagrapi
 
22
  # print(
23
  # os.environ.get("INSTA_USERNAME"), os.environ.get("INSTA_PASSWORD")/
24
 
@@ -92,10 +93,26 @@ os.makedirs(os.path.dirname(INSTA_COOKIE_PATH), exist_ok=True)
92
  app = Quart("Auto notifier thingy")
93
  cache = dc.Cache('/tmp/cache_dir/')
94
 
95
- x_client = Client('en-US')
96
  insta_client = instagrapi.Client()
97
  reddit_client = None
98
- threads_client = Threads()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  async def login_instagram():
101
  if not os.path.exists(INSTA_COOKIE_PATH):
 
19
  from threads_util.main import Threads
20
  import asyncpraw
21
  import instagrapi
22
+ import time
23
  # print(
24
  # os.environ.get("INSTA_USERNAME"), os.environ.get("INSTA_PASSWORD")/
25
 
 
93
  app = Quart("Auto notifier thingy")
94
  cache = dc.Cache('/tmp/cache_dir/')
95
 
96
+ x_client = Client('en-US')
97
  insta_client = instagrapi.Client()
98
  reddit_client = None
99
+
100
+ # Retry logic for Threads() instantiation
101
+ max_attempts = 5
102
+ for attempt in range(1, max_attempts + 1):
103
+ try:
104
+ threads_client = Threads()
105
+ print("Threads client created successfully.")
106
+ break # Exit loop if successful
107
+ except Exception as e:
108
+ print(f"Attempt {attempt} failed: {e}")
109
+ traceback.print_exc()
110
+ if attempt < max_attempts:
111
+ print("Retrying in 5 seconds...")
112
+ time.sleep(5)
113
+ else:
114
+ print("Max attempts reached. Raising exception.")
115
+ raise
116
 
117
  async def login_instagram():
118
  if not os.path.exists(INSTA_COOKIE_PATH):