'파이썬'에 해당하는 글 1건





# 코드
import threading, time

def proc(res):
    print("start", res)
    time.sleep(3)
    print("end")

t = threading.Thread(target=proc, args=("abc"))
t.start()

# 결과
PS C:\project\unity\MyQuant\python> python3 .\pg.py
Exception in thread Thread-1 (proc):
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
TypeError: proc() takes 1 positional argument but 3 were given

간단한 코드인에 요런 에러가 발생합니다.

이 문제는 왜 발생하냐면요

t = threading.Thread(target=proc, args=("abc"))
 
부분이 문제입니다.

한개만 넣으면 정상적으로 처지가 되지 않나봅니다.

t = threading.Thread(target=proc, args=("abc", )) 

이런식으로 , 콤마가 필요합니다. 배열로 들어가야하나봅니다.

즐 코딩

 

 


WRITTEN BY
SIDNFT
게임개발자에서 WEBGL 웹개발자로 전환중

,