1
다음은 파이썬 코드입니다. 장식은 threading.thread에서 상속받은 클래스를 통해 만들어진 스레드가 없어도 괜찮습니다. 예를 들어 FUNC 나는 아래와 같이 오류 정보를 가지고Python 장식에서 스레딩 lib를 사용하여 func의 매개 변수를 가져올 수 없습니까?
import threading ,time
from time import sleep, ctime
import functools
def find(func):
@functools.wraps(func)
def wrapper(*args,**kwargs):
print("ags:%s,%s\n" % (args,kwargs))
return func(*args, **kwargs)
return wrapper
@find
def now() :
return str(time.strftime('%Y-%m-%d %H:%M:%S' , time.localtime()))
class myThread (threading.Thread) :
"""docstring for myThread"""
@find
def __init__(self, nloop, nsec) :
super(myThread, self).__init__()
self.nloop = nloop
self.nsec = nsec
@find
def run(self):
print('start loop', self.nloop, 'at:', ctime())
sleep(self.nsec)
print('loop', self.nloop, 'done at:', ctime())
@find
def main():
thpool=[]
print('starting at:', now())
for i in range(10):
thpool.append(myThread(i,2))
for th in thpool:
th.start()
for th in thpool:
th.join()
print('all Done at:', now())
if __name__ == '__main__':
main()
) (threading.thread하는 paremeter로 대상을 제공하여 스레드를 생성합니다
File "F:\question\multithreadfmclass.py", line 15, in wrapper
print("ags:%s,%s\n" % (args,kwargs))
File "D:\ProgramFiles\Python352\lib\threading.py", line 813, in __repr__
assert self._initialized, "Thread.__init__() was not called"
AssertionError: Thread.__init__() was not called
어떻게 버그를 제거하려면? 사전에.