reloadware / reloadium

Hot Reloading and Profiling for Python
https://reloadium.io
Apache License 2.0
2.74k stars 56 forks source link

Notification After Modifying .py File: xx Has Been Modified but Not Loaded Yet. Hot Reloading Not Needed. #161

Open saltyplum opened 10 months ago

saltyplum commented 10 months ago

I've made sure that this file has been successfully loaded. I added a print statement at the very beginning of the file, and it outputs correctly when the program starts. Additionally, when calling this function in debug mode, it successfully locates the function.

saltyplum commented 10 months ago

I am using reloadium on the zhenxun_bot project, which is a chatbot developed based on the nonebot2 framework. After testing, I found that the "xx Has Been Modified but Not Loaded Yet." message appears mainly in the plugins module. All other modules can be reloaded properly, while the loading method for plugins is as follows:

import nonebot
nonebot.init()
# Load plugins
nonebot.load_plugins("src/plugins")
nonebot.run()

The loading of plugins is completed in the robot's entry file and needs to be done after framework initialization and before running. I'm not sure if the loading method is causing the issue, and if it is, I hope to have support added for this situation. Thank you.

saltyplum commented 10 months ago

It doesn't work only in the __init__.py file, but it works in other .py files.

dkrystki commented 10 months ago

Could you provide a reproducer (minimal code that reproduces the issue). I'll try fixing it in the next release if you provide this.

saltyplum commented 10 months ago

The issue arises with the __init__.py file in Nonebot 2 plugin development. If you directly modify the __init__.py file, these modifications won't be hot-reloaded correctly. However, if you create a test.py file and import it in the __init__.py file, modifications made to the test.py file can be hot-reloaded successfully. eg: __init__.py file

from nonebot import on_command
test = on_command("test")
@test.handle()
async def _():
    print('test')
saltyplum commented 9 months ago

https://nonebot.dev/docs/2.0.1/tutorial/create-plugin