Jalcock501
Jalcock501

Reputation: 399

TypeError: Popen not iterable

Am re-writing a program from previous question, and I am having trouble with it. Please see code:

#!/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

When trying to run the code I get the following error:

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

This code worked before I seperated the subprocess and set up __ReadRX__ as a seperate process.

Coudl anyone explain what is happening as I don't quite understand?

Upvotes: 0

Views: 206

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43196

(procRX) doesn't create a tuple, you have to use (procRX,).

Upvotes: 2

Related Questions