Hi, I’m creating a simple program in python using socket and threading module. I have created inside a class a subclass containing all the decorators (I saw this technique at this link) as follows:
class Server(object):
class Decorators(object):
@classmethod
def make_threaded(cls, function):
def inner(*args):
function_thread = threading.Thread(target=function, args=args)
function_thread .start()
return function_thread
return inner
@Decorators.make_threaded
def simple_function(self):
def inner1():
pass
def inner2():
pass
Therefore, I would like to decorate the inner1 and inner2 functions as well using the same decorator. But, when I try to to rewrite the function as:
@Decorators.make_threaded
def simple_function(self):
@Decorators.make_threaded
def inner1():
pass
@Decorators.make_threaded
def inner2():
pass
I get an error: NameError: name ‘Decorators’ is not defined. How can I avoid this error and implement the decorator in the inner1,2 functions as well?
Thank you very much for your time and excuse my english, I’m still practising it!