0

Good evening everyone. Guys I'm implementing a function that processes network packets. At the moment I'm using a while loop so that the function is always running, but I would like to set a time in ms and at the end of that time the loop ends. Can you give me a tip? A snippet of my loop so far:


    while True:
               
        status = pcap.loop(pd, 0, processing_pkts,
            ct.cast(ct.pointer(packet_count), ct.POINTER(ct.c_ubyte)))
        if status < 0:
            break
            

Thanks for any tips!!!

D-LA
  • 17
  • 4

1 Answers1

0
import time
end_time = time.time() + 60 * 10  //this will run for 600 seconds
while time.time() < end_time:
   // do your work
Tharanga Abeyseela
  • 3,255
  • 4
  • 33
  • 45