I am trying to figure out a way to detect "application reload" so that I can close the APScheduler thread pool.
I think there is no easy way for sure to detect a restart of the application, but uwsgi can execute the code after rebooting or closing, as follows:
1) The code will be executed in a separate process: add hook-as-user-atexit to the uwsgi configuration:
[uwsgi] ... hook-as-user-atexit = exec:python finalization.py
2) Will be called in one of the workers:
import uwsgi def will_invoked_after_reload_or_shutdown(): print("I was invoked") uwsgi.atexit = will_invoked_after_reload_or_shutdown
3) In this case, you must restart touch uwsgi.pid . It will be called by one of the workers, only after a reboot:
[uwsgi] ... pidfile = ./uwsgi.pid touch-reload = ./uwsgi.pid
Python Code:
import uwsgi def will_executed_after_reload(*args): print("I was invoked") uwsgi.register_signal(17, "worker", will_executed_after_reload) uwsgi.add_file_monitor(17, "./uwsgi.pid")
Greg eremeev
source share