feat: 热更新和热重载功能

This commit is contained in:
Rock Chin
2023-01-01 22:52:27 +08:00
parent 887b9e89e8
commit 3b1a72358e
4 changed files with 60 additions and 0 deletions

19
pkg/utils/reloader.py Normal file
View File

@@ -0,0 +1,19 @@
import logging
import pkg
import importlib
import pkgutil
def walk(module, prefix=''):
for item in pkgutil.iter_modules(module.__path__):
if item.ispkg:
walk(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.')
else:
logging.info('reload module: {}'.format(prefix + item.name))
importlib.reload(__import__(module.__name__ + '.' + item.name, fromlist=['']))
def reload_all():
walk(pkg)
importlib.reload(__import__('config'))