TypeError: 'pcapObject' object is not iterable

#!/usr/bin/env python2
from multiprocessing import Process
import pcap
import sys
import string
from multiprocessing import Pool


def capture_f(p):
    # print "Size Of Queue: %d" %n
    return p.next()


def parsing_f(buffer):
    print len(buffer)

p = pcap.pcapObject()
packet_buffer = []
pool = Pool(4)
if len(sys.argv) < 3:
    print 'usage: sniff.py <interface> <expr>'
    sys.exit(0)
dev = sys.argv[1]
p.open_live(dev, 1600, 0, 100)
p.setfilter(string.join(sys.argv[2:], ' '), 0, 0)

try:
    while 1:
        packet_buffer = pool.map(capture_f, p)
        temp_buffer = packet_buffer
        del packet_buffer[:]
        radius_reader = Process(target=parsing_f, args=(temp_buffer,))
        radius_reader.daemon = True
        radius_reader.start()

except KeyboardInterrupt:
    print '%s' % sys.exc_type
    print 'shutting down'
    print '%d packets received, %d packets dropped, %d packets dropped by interface' % p.stats()

But i am getting exception:

Traceback (most recent call last): File "script.py", line 29, in packet_buffer = pool.map(capture_f, p) File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/python2.7/multiprocessing/pool.py", line 304, in map_async iterable = list(iterable) TypeError: 'pcapObject' object is not iterable

All i want is to capture packets in multiprocessing pool. Any help would be appreciated. Thanx in advance.

链接地址: http://www.djcxy.com/p/9422.html

上一篇: 使用Python 2.7 / Windows运行多处理作业

下一篇: TypeError:'pcapObject'对象不可迭代