在一定时间之后结束脚本的执行-Python

发布于 2025-02-04 14:46:52 字数 400 浏览 2 评论 0原文

晚上好,大家。我正在实施一个处理网络数据包的函数。目前,我使用了一段时间的循环,以使该功能始终运行,但是我想在MS中设置时间,并在那段时间结束时循环结束。你能给我一个小费吗?到目前为止,我的循环片段:


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

感谢您的任何提示!!!

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!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2025-02-11 14:46:53
import time
end_time = time.time() + 60 * 10  //this will run for 600 seconds
while time.time() < end_time:
   // do your work
import time
end_time = time.time() + 60 * 10  //this will run for 600 seconds
while time.time() < end_time:
   // do your work
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文