【问题标题】:pyshark packets queue and pickle errorspyshark 数据包队列和泡菜错误
【发布时间】:2015-02-26 15:41:27
【问题描述】:

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

当我尝试从 multiprocessing.Queueun-pickle 获取数据包时出现以下错误:

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 这样做有问题?

【问题讨论】:

    标签: python python-2.7 pyshark


    【解决方案1】:

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

    这是因为某些类数据包使用了覆盖 getattr。修复于541fc52

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多