2012-11-30 14 views
26

Sto lavorando su Python e sto provando ad eseguire un thread che richiede 1 parametro "q", ma quando sto cercando di eseguirlo si verifica una strana eccezione, ecco il mio codice:Eccezione nella discussione: deve essere una sequenza, non un'istanza

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() 

viene a mancare con il seguente errore:

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 

non devo idea di cosa sta succedendo! Aiuto per favore!

+0

Vedere anche: http://stackoverflow.com/q/37400133/1240268 (per coloro che vedono questa eccezione perché il loro tipo non ha definito star-unpacking). –

risposta

43

Il parametro args-threading.Thread dovrebbe essere una tupla e si sta passando (q) che non è - è lo stesso di q.

Immagino che tu volessi una tupla a 1 elemento: dovresti scrivere (q,).

+1

Grazie @Tibo! Ha funzionato sharm! – karensantana

Problemi correlati