Comments (3)
To follow up, there were only a few things that I needed to modify to get this to work for me and @jourdain. Here's a diff:
diff --git a/reloading/reloading.py b/reloading/reloading.py
index aef1353..8401a81 100644
--- a/reloading/reloading.py
+++ b/reloading/reloading.py
@@ -181,14 +181,17 @@ def _reloading_loop(seq, every=1):
def get_decorator_name(dec_node):
if hasattr(dec_node, "id"):
return dec_node.id
- return dec_node.func.id
+ elif hasattr(dec_node.func, "id"):
+ return dec_node.func.id
+ return dec_node.func.value.id
def strip_reloading_decorator(func):
- """Remove the reloading decorator in-place"""
- func.decorator_list = [
- dec for dec in func.decorator_list if get_decorator_name(dec) != "reloading"
- ]
+ """Remove the 'reloading' decorator and all decorators before it"""
+ decorator_names = [get_decorator_name(dec) for dec in func.decorator_list]
+ reloading_idx = decorator_names.index("reloading")
+ func.decorator_list = func.decorator_list[reloading_idx + 1:]
Basically, the method to get the decorator name for @ctrl.set("update_message")
was not working for some reason. But adding a check for "id" on the func object, and then trying dec_node.func.value.id
, worked for us (this returns ctrl
).
The second part of our issue is that on the current master branch, all decorators are reloaded except the @reloading
decorator. I believe, however, it may make more sense to only reload decorators after the @reloading
decorator. This is because if we set up decorators like this:
@decorator
@reloading
def func():
pass
Then the @decorator
there is going to be taking the reloading-wrapped function at first, but the first time it is called, this reloading-wrapper gets removed since it is reloaded without the @reloading
.
This was the issue with our code. The @ctrl.set("update_message")
decorator is setting the function to a global object, and when it is first defined, the function is the reloading-wrapped function. But as soon as it gets called for the first time, the @ctrl.set("update_message")
is executed again, and it replaces the reloading-wrapped function with a static, non-reloading function. So the reloading would no longer work after the first time.
I also think it logically makes more sense to only reload what comes after @reloading
.
@julvo If you agree with these changes, I am happy to put up a PR.
from reloading.
Thank you both for reporting and looking into this.
Both suggested changes make sense to me and I'd be happy to merge a PR with these.
For the decorator name lookup in the first change: I guess we could be even more defensive here, name the function get_decorator_name_or_none
and check that any attribute exists before we access it and return None
otherwise instead of crashing.
from reloading.
@julvo Great, thank you! I just made a PR that includes your suggestion.
from reloading.
Related Issues (16)
- Performance improvement: option to only reload every n iterations
- Chore: update/add documentatio for reloading every n loops HOT 2
- improvement: check file change date/hash and only reload if changed HOT 2
- Locate reloading loops in source by something other than line number HOT 1
- patch for #5 issue
- how can I debug the reloading code step by step in IDE such as vscode? HOT 1
- Reload class and methods inside, reload for-loop within function which has 'return', 'continue', 'break' statements HOT 3
- Fix README.md instructions HOT 1
- Not support chinese
- Error using VS-Code and reloading v1.1.2 HOT 2
- List index error when files lacks ending \n HOT 1
- Pull request for local variable overwrite bug HOT 3
- AttributeError: 'Attribute' object has no attribute 'id' HOT 3
- Condaforge
- KeyError: '__inner__' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reloading.