From ac8fad3a1868f4a3cb8b98caa76e6078c39e9f67 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Jan 2020 22:01:10 +0100 Subject: [PATCH] Fix plugin modules not being properly reloaded from disk When using importlib.import_module, Python loads the module from disk only once and any subsequent call to this method will just re-import the already loaded module from RAM. Wrapping importlib.import_module with importlib.reload will make Python force-reload the module from disk. --- pyrogram/client/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 10b3ba2a..3d3ddd11 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -26,7 +26,7 @@ import threading import time from configparser import ConfigParser from hashlib import sha256, md5 -from importlib import import_module +from importlib import import_module, reload from pathlib import Path from signal import signal, SIGINT, SIGTERM, SIGABRT from threading import Thread @@ -1531,7 +1531,7 @@ class Client(Methods, BaseClient): if not include: for path in sorted(Path(root).rglob("*.py")): module_path = '.'.join(path.parent.parts + (path.stem,)) - module = import_module(module_path) + module = reload(import_module(module_path)) for name in vars(module).keys(): # noinspection PyBroadException @@ -1553,7 +1553,7 @@ class Client(Methods, BaseClient): warn_non_existent_functions = True try: - module = import_module(module_path) + module = reload(import_module(module_path)) except ImportError: log.warning('[{}] [LOAD] Ignoring non-existent module "{}"'.format( self.session_name, module_path)) @@ -1591,7 +1591,7 @@ class Client(Methods, BaseClient): warn_non_existent_functions = True try: - module = import_module(module_path) + module = reload(import_module(module_path)) except ImportError: log.warning('[{}] [UNLOAD] Ignoring non-existent module "{}"'.format( self.session_name, module_path))