2015-01-08 70 views
0

我正在重寫前一個問題的程序,而且我遇到了問題。請參閱代碼:TypeError:Popen無法迭代

#!/usr/bin/python 

import subprocess,time, timeit 
from multiprocessing import Process, Queue 
import re, os, pprint, math 
from collections import defaultdict 

Dict = {} 
identifier = "" 
hexbits = [] 
count = defaultdict(int) 

def __ReadRX__(RX_info): 
    lines = iter(RX_info.stdout.readline, "") 
    try: 
     start = time.clock() 
     for line in lines: 
      if re.match(r"^\d+.*$",line): 
       splitline = line.split() 
       del splitline[1:4] 
       identifier = splitline[1] 
       count[identifier] += 1 
       end = time.clock() 
       timing = round((end - start) * 10000, 100) 
       dlc = splitline[2] 
       hexbits = splitline[3:] 
       Dict[identifier] = [dlc, hexbits, count[identifier],int(timing)] 
       start = end 
    except keyboardinterrupt: 
     pass 

procRX = subprocess.Popen('receivetest -f=/dev/pcan32'.split(), stdout=subprocess.PIPE) 

if __name__ == '__main__': 
    munchCan = Process(target=__ReadRX__, args=(procRX)) 
    munchCan.start() 
    munchCan.join() 
    print Dict 

當試圖運行代碼我得到以下錯誤:

File "./cancheck2.py", line 36, in <module> 
    munchCan = Process(target=__ReadRx__, args=(procRX)) 
File "/usr/lib/python2.7/multiprocessing/process.py", line 104, in __init__ 
    self._args = tuple(args) 
TypeError: 'Popen' objec is not iterable 

之前分隔我子進程並設置__ReadRX__作爲一個獨立的過程此代碼工作。

Coudl任何人都解釋發生了什麼,因爲我不太明白?

回答

2

(procRX)不創建元組,您必須使用(procRX,)

+0

我是個白癡....謝謝! – Jalcock501