dispatch_after

//想在指定时间后执行处理的情况,可使用dispatch_after函数来实现。
//dispatch_after函数并不是在指定的时间后执行处理,而只是在指定的时间追加处理到Dispatch Queue。
//通过dispatch_after在3秒后将指定的block追加到Main Dispatch Queue
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW,3ull*NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
NSLog(@"1秒后");
});
//参数1:指定时间用的dispatch_time_t类型的值,该值使用dispatch_time函数或dispatch_walltime函数作成。
//参数2:指定要追加处理的Dispatch Queue
//参数3:指定记述要执行处理的Block
//注:因为Main Dispatch Queue在主线程的RunLoop中执行,所以在比如每隔1/60秒执行的RunLoop中,Block最快在3秒后执行,最慢在3秒+1/60秒后执行,并且在Main Dispatch Queue有大量处理追加或主线程的处理本身有延迟时,这个时间会更长。虽然在有严格时间的要求下使用时会出现问题,但在想大致延迟执行处理时,该函数是非常有效的。
//dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW,3ull*NSEC_PER_SEC);
//dispatch_time函数能够获取从第一个参数dispatch_time_t类型值中指定的时间开始,到第二个参数指定的毫微秒单位时间后的时间。DISPATCH_TIME_NOW表示现在的时间。第二个参数中用秒和NSEC_PER_SEC的相乘来表示,毫秒和NSEC_PER_MSEC相乘来表示。ull即unsigned long long
//dispatch_walltime函数用于计算绝对时间,如某个具体的时间。而dispatch_time通常用于计算相对时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误怎么解决:192.168.34.71 - - [14/Jan/2023 22:41:01] "GET /get_nb2_ip/ HTTP/1.1" 500 - Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2548, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2528, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1823, in full_dispatch_request return self.finalize_request(rv) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1842, in finalize_request response = self.make_response(rv) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2170, in make_response raise TypeError( TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a Response.代码是这个:@app.route('/get_nb2_ip/') def get_nb2_ip(): #curl -i --basic -u admin:public -X GET "http://192.168.34.131:8081/api/v4/clients?_page=1&_limit=10" response = requests.get('http:192.168.34.131:8081/api/v4/clients?_page=1&_limit=10', auth=('admin', 'public')) return response
最新发布
02-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值