0

我正在尝试使用pyshark实时捕获数据包。

当我尝试从 a 获取数据包multiprocessing.Queue取消它们时出现以下错误:

python2.7/site-packages/pyshark/packet/layer.py",第 48 行,在 __getattr__
val = self.get_field_value(item, raw=self.raw_mode)
(...多次...)
RuntimeError:最大递归调用 Python 对象时超出深度。

我怀疑在重建对象时存在问题,无论它是从队列中检索的,还是未腌制的。
但令人惊讶的是,当我使用Queue.Queue.

这是用于重现此问题的代码:

import pyshark
import multiprocessing
import Queue
import cPickle as pickle

# Capture on eth0
interface = pyshark.LiveCapture(interface="eth0")

def queue_test(queue):
    """ Puts captured packets in a queue, then un-queue them and display """
    for packet in interface.sniff_continuously(packet_count=5):
        queue.put(packet)
    while not queue.empty():
        packet = queue.get()
        print "Packet {} {}".format(packet.highest_layer,packet._packet_string)

def pickle_test():
    """ Immediately pickle and unpickle the packet to display it"""
    for packet in interface.sniff_continuously(packet_count=5):
        pickled_packet = pickle.loads(pickle.dumps(packet, pickle.HIGHEST_PROTOCOL))
        print "Packet #{}, {} {}".format(pickled_packet.highest_layer,pickled_packet._packet_string)


if __name__ == "__main__":
    normal_queue = Queue.Queue()
    process_queue = multiprocessing.Queue()

    # Runs fine
    queue_test(normal_queue)

    # Both crash with a RuntimeError
    queue_test(process_queue)
    pickle_test()

为什么我会收到 RuntimeErrors,我该怎么办?
我做错了什么还是pyshark有问题?

4

1 回答 1

0

pyshark在这里没有太大的成功,我在's Github上发布了一个问题,碰巧它在库中丢失了一些东西:

这是由于某些类数据包使用覆盖 getattr 的事实引起的。已在541fc52中修复

本期链接:https ://github.com/KimiNewt/pyshark/issues/63

于 2015-03-02T07:46:31.910 回答