coollsd commited on
Commit
a5ce025
·
verified ·
1 Parent(s): 881d825

Update ccc.py

Browse files
Files changed (1) hide show
  1. ccc.py +5 -22
ccc.py CHANGED
@@ -149,7 +149,7 @@ async def print_status_periodically():
149
  print("Working")
150
  await asyncio.sleep(60)
151
 
152
- async def scanner_main():
153
  initialize_base_ids()
154
  tasks = []
155
  instances_per_digit = 20000
@@ -161,26 +161,9 @@ async def scanner_main():
161
  tasks.append(print_status_periodically())
162
  await asyncio.gather(*tasks)
163
 
164
- def run_server_and_scanner():
165
- loop = asyncio.new_event_loop()
166
- asyncio.set_event_loop(loop)
167
-
168
- scanner_task = loop.create_task(scanner_main())
169
- api_task = loop.create_task(
170
- uvicorn.run(
171
- app,
172
- host="0.0.0.0",
173
- port=7860,
174
- loop=loop
175
- )
176
- )
177
-
178
- try:
179
- loop.run_forever()
180
- except KeyboardInterrupt:
181
- pass
182
- finally:
183
- loop.close()
184
 
185
  if __name__ == "__main__":
186
- run_server_and_scanner()
 
149
  print("Working")
150
  await asyncio.sleep(60)
151
 
152
+ async def start_scanner():
153
  initialize_base_ids()
154
  tasks = []
155
  instances_per_digit = 20000
 
161
  tasks.append(print_status_periodically())
162
  await asyncio.gather(*tasks)
163
 
164
+ @app.on_event("startup")
165
+ async def startup_event():
166
+ asyncio.create_task(start_scanner())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  if __name__ == "__main__":
169
+ uvicorn.run(app, host="0.0.0.0", port=7860)