【问题标题】:TypeError: Popen not iterableTypeError:Popen 不可迭代
【发布时间】:2015-03-06 13:19:45
【问题描述】:

我正在重写上一个问题的程序,但我遇到了麻烦。请看代码:

#!/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__ 设置为单独的进程之前有效。

如果我不太明白,谁能解释发生了什么?

【问题讨论】:

    标签: python linux multiprocessing subprocess popen


    【解决方案1】:

    (procRX) 不会创建元组,您必须使用(procRX,)

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 2011-02-18
      • 2017-02-21
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多