让函数在Python中工作一段时间 [英] Let function work for amount of time in Python

查看:100
本文介绍了让函数在Python中工作一段时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们

我想知道如何让一个函数在一段时间内工作

i一直在建立一个网络爬虫来收集来自一个certin页面和其中一个功能我需要它工作一段时间然后再睡觉一段时间然后工作等.....

任何想法这里



我尝试了什么:



i尝试睡眠功能,它只是推迟了工作

解决方案

您只需要捕获函数启动的时间,然后定期检查它是否已达到其时间限制。然后你睡觉分配休息时间,然后重复整个过程。请参见 15.3。时间 - 时间访问和转换& mdash; Python 2.7.12文档 [ ^ ]

hey guys
i'm wondering on how to let a function to work for a certin amount of time
i have been building a web crawler to gather links from a certin page and one of the functions i need it to work for amount of time then goes to sleep for another amount of time then work etc.....
any idea here

What I have tried:

i tried sleep function and it's only delaying the work

解决方案

You just need to capture the time when your function starts, and then periodically check whether it has reached its time limit. you then sleep for the allotted rest time and then repeat the whole process. See 15.3. time — Time access and conversions — Python 2.7.12 documentation[^].


这篇关于让函数在Python中工作一段时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆