1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added reloader to ext

This commit is contained in:
coder2020official 2022-08-30 21:24:54 +04:00
parent 095bf03227
commit e0ffe0b4f5

27
telebot/ext/reloader.py Normal file
View File

@ -0,0 +1,27 @@
from watchdog.events import FileSystemEventHandler
from watchdog.events import FileSystemEvent
import psutil
import os
import sys
import logging
logger = logging.getLogger('TeleBot')
class EventHandler(FileSystemEventHandler):
def on_any_event(self, event: FileSystemEvent):
logger.info('* Detected changes in: %s , reloading', (event.src_path))
restart_file()
def restart_file():
try:
p = psutil.Process(os.getpid())
for handler in p.open_files() + p.connections():
os.close(handler.fd)
except Exception as e:
logger.error(e)
python = sys.executable
os.execl(python, python, *sys.argv)