TISUnion / PrimeBackup

A powerful backup plugin for MCDR, an advanced backup solution for your Minecraft world
https://tisunion.github.io/PrimeBackup/
GNU Lesser General Public License v3.0
81 stars 5 forks source link

无法使用mcdr的卸载插件指令卸载 #4

Closed Crystal0404 closed 10 months ago

Crystal0404 commented 10 months ago

环境

MCDR版本2.12.2 PrimeBackup版本1.3.0 Python版本3.11.4

复现

首次启动pb,无需更改配置文件,使用指令!!MCDR plg disable prime_backup后控制台就会报错

报错日志

[MCDR] [2023-12-15 14:22:44] [TaskExecutor/INFO]: 共重载: §71§r 个插件; 已加载插件数: §73§r
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO]: 正在禁用插件 prime_backup@1.3.0
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO]: 正在卸载插件 prime_backup@1.3.0
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO] [prime_backup]: Shutting down everything...
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO] [prime_backup]: Shutdown completes
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO]: 插件 prime_backup@1.3.0 已卸载
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO]: 插件 "§eprime_backup@1.3.0§r" 禁用§c失败§r
[MCDR] [2023-12-15 14:22:47] [TaskExecutor/ERROR]: Traceback (most recent call last):
  File "D:\Python\mcdr\mcdr\Lib\site-packages\mcdreforged\plugin\builtin\mcdreforged_plugin\commands\sub_command.py", line 93, in function_call
    ret = FunctionCallResult(func(), True)
                             ^^^^^^
  File "D:\Python\mcdr\mcdr\Lib\site-packages\mcdreforged\plugin\builtin\mcdreforged_plugin\commands\plugin_command.py", line 172, in <lambda>
    self.__execute_and_report_plugin_manipulate(source, operation_name, lambda: func(plugin), plugin.get_name(), result_type_to_check_success)
                                                                                ^^^^^^^^^^^^
  File "D:\Python\mcdr\mcdr\Lib\site-packages\mcdreforged\plugin\plugin_manager.py", line 554, in disable_plugin
    future.add_done_callback(done_callback)
  File "D:\Python\mcdr\mcdr\Lib\site-packages\mcdreforged\utils\future.py", line 50, in add_done_callback
    callback(self.get())
  File "D:\Python\mcdr\mcdr\Lib\site-packages\mcdreforged\plugin\plugin_manager.py", line 550, in done_callback
    os.rename(plugin.plugin_path, plugin.plugin_path + plugin_constant.DISABLED_PLUGIN_FILE_SUFFIX)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'plugins\\PrimeBackup-v1.3.0.pyz' -> 'plugins\\PrimeBackup-v1.3.0.pyz.disabled'

[MCDR] [2023-12-15 14:22:47] [TaskExecutor/INFO]: 插件 "§eprime_backup@1.3.0§r" 禁用§c失败§r

其他行为

如果在配置中启用pb,再使用!!MCDR plg disable prime_backup禁用,此时依旧会报错,但是!!pb已不可用,重启服务器或者重载插件就会恢复使用

Fallen-Breath commented 10 months ago

无法复现。环境如下:(upd:此处环境有误,见下方评论 https://github.com/TISUnion/PrimeBackup/issues/4#issuecomment-1857378420

请确保 PrimeBackup-v1.3.0.pyz 没有被任何其他进程占用

Fallen-Breath commented 10 months ago
  • Python 3.11.6

诶不对,这里的 Python 版本有误。Python 3.9.12 无法复现此 issue,但是 Python 3.11.6 可复现此 issue

Fallen-Breath commented 10 months ago

在 Windows 平台下,Python 3.10 及以后,对于所有类型的 MCDR 打包插件,只要进行了如下的 import 操作

import apscheduler.schedulers.base

就会导致打包插件文件在 Windows 下被占用。暂不清楚这是 Python 的问题、还是 apscheduler 的问题,还是 MCDR 的问题。但至少这不是本插件能解决的问题

Fallen-Breath commented 10 months ago

经过分析,已得出该 issue 的原因:apscheduler 在 apscheduler.schedulers.base.BaseScheduler 的类定义中,调用了 importlib.metadata.entry_points 函数,最终因 Python 的 importlib 库的内部实现机制,引发了 https://github.com/Fallen-Breath/MCDReforged/issues/283

上述 apscheduler 的相关代码见: https://github.com/agronholm/apscheduler/blob/677ce711a5381c3d44f4c6313098844d26b70666/apscheduler/schedulers/base.py#L75-L77

关于如何解决本 issue,请等待 MCDR 对相关问题进行兼容修复,然后更新 MCDR 的版本,即可

Fallen-Breath commented 10 months ago

你可以尝试使用这个 MCDR 的开发版本,应该已经修复了这个问题 https://test.pypi.org/project/mcdreforged/2.12.2.dev639/