mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Do not start server when importing the main.py file, unless gunicorn
- Add more graceful shutdown when closing bg scheduler thread
This commit is contained in:
parent
be3ee5ec9f
commit
c1a5b32ebf
1 changed files with 7 additions and 3 deletions
|
@ -109,7 +109,10 @@ def shutdown_scheduler():
|
|||
logger.info("🔓 Schedule Leader released")
|
||||
ProcessLockAdapters.remove_process_lock(state.schedule_leader_process_lock)
|
||||
|
||||
state.scheduler.shutdown()
|
||||
try:
|
||||
state.scheduler.shutdown()
|
||||
except Exception as e:
|
||||
logger.debug(f"Did not shutdown scheduler: {e}")
|
||||
|
||||
|
||||
def run(should_start_server=True):
|
||||
|
@ -237,5 +240,6 @@ def poll_task_scheduler():
|
|||
if __name__ == "__main__":
|
||||
run()
|
||||
else:
|
||||
run(should_start_server=False)
|
||||
atexit.register(shutdown_scheduler)
|
||||
if "gunicorn" in sys.modules:
|
||||
run(should_start_server=False)
|
||||
atexit.register(shutdown_scheduler)
|
||||
|
|
Loading…
Reference in a new issue