python - 为什么这段代码给出了“PicklingError:不能pickle <type'function'=”“>:属性查找__builtin __。函数失败”错误?

时间:2017-03-21 04:32:26

标签: python

我似乎无法找到解决此问题的方法。

from scapy.all import *
from multiprocessing import Process, Queue
from threading import Lock

pkts = []    
lock = Lock()

def MyPrint(que):
    count = 0
    while 1:
        if que.qsize() == 0 :
            continue
        pkts.append(que.get())
        print '%d packet' % count
        print pkts[count].sprintf("Source:{IP:%IP.src%}:{TCP:%TCP.sport%} ===> Dest:{IP:%IP.dst%}:{TCP:%TCP.dport%}\n: {Raw:%Raw.load%}\n\n")
        count = count + 1

def CollectPacket(x, que):
    lock.acquire()
    que.put(x)
    lock.release()

def MySniffing(que):
    sniff(filter='ip host 172.20.64.12', prn=lambda x: CollectPacket(x, que))

def main():
    que = Queue()
    pr1 = Process(target=MySniffing, args=(que, ))
    pr2 = Process(target=MyPrint, args=(que,))

    pr1.start()
    pr2.start()

if __name__ == '__main__':
    main()

这会产生以下输出:

Traceback (most recent call last):
  File "C:\Python27\lib\multiprocessing\queues.py", line 264, in _feed
    send(obj)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

0 个答案:

没有答案