2012-11-30 2 views
26

임 파이썬에서 작업 중이며 1 매개 변수 "q"를 사용하는 스레드를 실행하려고하는데, 이상한 예외가 발생하면 여기에 코드가 있습니다 :스레드 예외 :

class Workspace(QMainWindow, Ui_MainWindow): 
    """ This class is for managing the whole GUI `Workspace'. 
     Currently a Workspace is similar to a MainWindow 
    """ 

    def __init__(self): 

     try: 
      from Queue import Queue, Empty 
     except ImportError: 
    #from queue import Queue, Empty # python 3.x 
      print "error" 

     ON_POSIX = 'posix' in sys.builtin_module_names 

     def enqueue_output(out, queue): 
      for line in iter(out.readline, b''): 
       queue.put(line) 
      out.close() 

     p= Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/',stdout=PIPE, shell=True, bufsize= 4024) 
     q = Queue() 

     t = threading.Thread(target=enqueue_output, args=(p.stdout, q)) 
     #t = Thread(target=enqueue_output, args=(p.stdout, q)) 

     t.daemon = True # thread dies with the program 
     t.start() 

# ... do other things here 
     def myfunc(q): 
      while True: 

       try: line = q.get_nowait() 
     # or q.get(timeout=.1) 
       except Empty: 
        print('') 
       else: # got line 
    # ... do something with line 
        print "No esta null" 
        print line 


     thread = threading.Thread(target=myfunc, args=(q)) 
     thread.start() 

그것은 다음과 같은 오류와 함께 실패합니다

Exception in thread Thread-2: 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner 
    self.run() 
    File "/usr/lib/python2.7/threading.py", line 504, in run 
    self.__target(*self.__args, **self.__kwargs) 
TypeError: myfunc() argument after * must be a sequence, not instance 

내가 무슨 일이 일어나고 있는지 생각을 가지고 있겠지! 제발 도와주세요!

+0

참조 : http://stackoverflow.com/q/37400133/1240268 (유형이 스타 언팩을 정의하지 않았으므로이 예외가 표시되는 경우). –

답변

43

threading.Threadargs 매개 변수는 튜플해야 당신이하지 않은 (q)를 전달하는 - 그것은 q과 동일합니다.

1 요소 튜플을 원했을 것입니다. (q,)을 작성해야합니다.

+1

감사합니다 @ 티보! 그것은 샴페인을했습니다! – karensantana

관련 문제