Background
I was reading Python decorators (where I'm a bit of rookie to the concept) and came across a part that emphasises the difference between 'import time' and 'runtime'.
So let's say I have a decorator function in one module called decorator_functions.py
and I have another module that houses bunch of decorated functions which is called decorated_objects.py
. When I import decorated_objects.py
somewhere else, Python creates bindings behind the scenes between the decorated objects and the relevant decorator before even the execution flow run them somewhere. My questions above arise at this point.
I have two questions:
- Do the bindings of a decorator stay with the decorated object for as long as the process is in use? That is, what is the lifetime of a decorator in Python after it is bound to an object?
- When a decorator is bound to multiple classes or modules which can be executed in multiple threads, are the decorated objects thread-safe? Or do I need to take care of synchronisation (or is there a built-in auto-sync method for decorators?
PS: I've seen this thread but it doesn't address my questions totally.