我正在尝试使用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
有问题?