数据打印不正确

Data not printing correct

当运行一个针对多处理的数据流子进程,在字典程序中打印一个元素后冻结,

#!/usr/bin/python

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

Dict = {}
count = defaultdict(int)
queueVar = Queue()

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 
                for identifier,hexbits in Dict.items():
                    queueVar.put(Dict)

    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()
    printDict = queueVar.get()
    for i in range(len(printDict)):
        print printDict

我知道如果我从 __ReadRX__ 打印它会打印一个恒定的流但是当尝试从函数外部打印时我只在字典中得到一个条目。

在顶部添加以下内容:

from time import sleep

然后在打印语句后添加:

sleep(1)

这将使脚本等待 1 秒。您可以根据需要调整该数字。