Stopping pyshark LiveCapture when no packets arrive on interface

21 Views Asked by At

I am using pyshark LiveCapture, processing packets using a callback supplied via apply_on_packets(). To avoid frequent restarts of dumpcap / tshark sub-processes, I am using apply_on_packets without a timeout parameter. The capture process shall be stopped programmatically, e.g. to suspend capturing, or to capture on another interface. This is possible throwing a StopCapture exception from within the callback.

But: How do I handle the case when there are no packets received on the currently selected interface? Since the callback is not called at all, no chance to throw the StopCapture exception. Is there an alternative way to interrupt the capturing process?

Tried to supply the eventloop to LiveCapture, and to stop / close the event loop when the capture process shall terminate. But this seems to trigger a lot of problems / exceptions in asyncio, so it is probably not the right way to go.

0

There are 0 best solutions below