python threading.Thread생성시 function argument 사용 주의점

threading.Thread 생성시 function argument 사용할때

name을 구분해주지 않으면 같은 name이 재시도 되지 않는다.
(name을 구분해야 제대로 돌아간다는말)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// 1)  좋은 

def func():
  pass

for i in range(3):
  th = threading.Thread(func())
  th.start()


// 2) 좋은 

def func():
  pass

for i in range(3):
  thName = 't%d' % i
  th = threading.Thread(func(), name=thName)
  th.start()

댓글 없음:

댓글 쓰기