Skip to content

Commit 6a7c346

Browse files
committed
supported MCDR v2.2 plugin suffix change (.pyz)
fixed dead lock when reloading itself v1.1.2
1 parent 0d6793e commit 6a7c346

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

auto_plugin_reloader/reloader.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from auto_plugin_reloader.common import tr, metadata, server_inst
1010

1111
ModifyTimeMapping = Dict[str, int]
12-
PLUGIN_FILE_SUFFIXES = ['.py', '.mcdr']
12+
PLUGIN_FILE_SUFFIXES = ['.py', '.mcdr', '.pyz']
1313

1414

1515
class Difference(NamedTuple):
@@ -32,6 +32,14 @@ def on_config_changed(self):
3232
else:
3333
self.stop()
3434

35+
@property
36+
def unique_hex(self) -> str:
37+
return hex((id(self) >> 16) & (id(self) & 0xFFFF))[2:].rjust(4, '0')
38+
39+
@property
40+
def unique_name(self) -> str:
41+
return '{} @ {}'.format(metadata.name, self.unique_hex)
42+
3543
def is_running(self):
3644
return self.__thread is not None and self.__thread.is_alive()
3745

@@ -40,7 +48,7 @@ def start(self):
4048
if not self.is_running():
4149
self.__stop_flag = False
4250
self.reset_detection_time()
43-
self.__thread = Thread(name=metadata.name, target=self.thread_loop)
51+
self.__thread = Thread(name='APR@{}'.format(self.unique_hex), target=self.thread_loop)
4452
self.__thread.start()
4553

4654
def join_thread(self):
@@ -66,8 +74,7 @@ def get_pretty_next_detection_time(self) -> RTextBase:
6674
return RText.format('{} ({})', time_text, tr('seconds_later', RText(round(time_next - time.time(), 1), RColor.gold)))
6775

6876
def thread_loop(self):
69-
unique_name = '{} @ {}'.format(metadata.name, hex((id(self) >> 16) & (id(self) & 0xFFFF))[2:].rjust(4, '0'))
70-
self.logger.info('{} started'.format(unique_name))
77+
self.logger.info('{} started'.format(self.unique_name))
7178
while not self.__stop_flag:
7279
while not self.__stop_flag and time.time() - self.last_detection_time < common.config.detection_interval_sec:
7380
time.sleep(0.005)
@@ -80,7 +87,7 @@ def thread_loop(self):
8087
self.stop()
8188
finally:
8289
self.reset_detection_time()
83-
self.logger.info('{} stopped'.format(unique_name))
90+
self.logger.info('{} stopped'.format(self.unique_name))
8491

8592
@staticmethod
8693
def scan_files() -> ModifyTimeMapping:
@@ -119,4 +126,8 @@ def check(self):
119126
self.logger.info('- {}: {}'.format(diff.file_path, diff.reason))
120127
self.logger.info(tr('triggered.footer'))
121128
self.scan_result = self.scan_files()
122-
server_inst.schedule_task(server_inst.refresh_changed_plugins, block=True)
129+
130+
holder = Thread(name='OperationHolder', daemon=True, target=lambda: server_inst.schedule_task(server_inst.refresh_changed_plugins, block=True))
131+
holder.start()
132+
while holder.is_alive() and not self.__stop_flag: # stop waiting after being stopped
133+
holder.join(timeout=0.01)

mcdreforged.plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "auto_plugin_reloader",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"name": "Auto Plugin Reloader",
55
"description": {
66
"en_us": "Automatically reload plugins when file changes",

0 commit comments

Comments
 (0)