Here is the case.
I start a telegram bot(using pyrogram framework) inside django and everytime that I modify a file and save it or django just restarts by any reason, I have to shut pyrogram down right before django starts again.
If I do not shut down pyrogram right before server restart process, it gets stuck after printing a sentence like:
<modified_file_address> changed, reloading.
And after this line, nothing happens and django will not start itself again and I just found source of the problem.
Pyrogram(v0.18.0 - synchronous version) is causing it because of multithreading lock keys.(a little bit complicated to describe and not related to the question)
If I can shutdown pyrogram bot right before running the django server again(literally right before or after printing <modified_file_address> changed, reloading.
message), I can fix it.
After searching inside the django source code, this is the function that actually prints that message.
# inside django.utils
def trigger_reload(filename):
logger.info('%s changed, reloading.', filename)
sys.exit(3)
And now this is my question:
Is There Any Way To Overwrite trigger_reload
Function Or Customize It Somehow?
And if no:
Is There Any Way To Run A Function Right Before trigger_reload
Function?
And if no again:
Is It Possible To Use Another Django Reloader And Customize It To Shutdown The Bot?
And if no again, what should I do?
Any suggestions?