我正在尝试使用pyshark来实时捕获数据包。
当我试图从multiprocessing.Queue获取数据包或不对它们进行腌制时,我会得到以下错误:
python2.7/site-packages/pyshark/packet/layer.py",第48行,以__getattr__表示 val =self.get_field_value(项目,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在做这件事上有问题?
https://stackoverflow.com/questions/28746662
复制相似问题