ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • python Exception in thread / 쓰레드 사용중 황당한 에러
    프로그래밍/개발메모 2022. 8. 3. 22:26
    728x90
    반응형
    # 코드
    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", )) 

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

    즐 코딩

     

     

    반응형
Designed by Tistory.