Skip to content

Commit ac8fad3

Browse files
committed
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.
1 parent 0f84f91 commit ac8fad3

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pyrogram/client/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import time
2727
from configparser import ConfigParser
2828
from hashlib import sha256, md5
29-
from importlib import import_module
29+
from importlib import import_module, reload
3030
from pathlib import Path
3131
from signal import signal, SIGINT, SIGTERM, SIGABRT
3232
from threading import Thread
@@ -1531,7 +1531,7 @@ def load_plugins(self):
15311531
if not include:
15321532
for path in sorted(Path(root).rglob("*.py")):
15331533
module_path = '.'.join(path.parent.parts + (path.stem,))
1534-
module = import_module(module_path)
1534+
module = reload(import_module(module_path))
15351535

15361536
for name in vars(module).keys():
15371537
# noinspection PyBroadException
@@ -1553,7 +1553,7 @@ def load_plugins(self):
15531553
warn_non_existent_functions = True
15541554

15551555
try:
1556-
module = import_module(module_path)
1556+
module = reload(import_module(module_path))
15571557
except ImportError:
15581558
log.warning('[{}] [LOAD] Ignoring non-existent module "{}"'.format(
15591559
self.session_name, module_path))
@@ -1591,7 +1591,7 @@ def load_plugins(self):
15911591
warn_non_existent_functions = True
15921592

15931593
try:
1594-
module = import_module(module_path)
1594+
module = reload(import_module(module_path))
15951595
except ImportError:
15961596
log.warning('[{}] [UNLOAD] Ignoring non-existent module "{}"'.format(
15971597
self.session_name, module_path))

0 commit comments

Comments
 (0)