简体   繁体   English

为什么Eventlet补丁修复了Celery任务中的requests.post?

[英]Why does Eventlet patch fix requests.post in Celery task?

I was having issues with Celery workers timing out due to multiple HTTP requests in my tasks. 由于我的任务中有多个HTTP请求,我遇到了Celery工作人员超时的问题。 I didn't understand why. 我不明白为什么。 It appeared that the tasks were just getting stuck at the first requests.post line (although not always). 似乎任务只是卡在第一个requests.post行(虽然并不总是)。 After finding a tangential SO answer regarding requests, I patched the requests library with: 在找到关于请求的切向SO答案后,我修改了请求库:

#import requests
import eventlet
requests = eventlet.import_patched("requests")

And everything is working very quickly and without issue now. 一切都很快,现在没有问题。

My question is: What voodoo sorcery is Eventlet doing to make my tasks work as expected? 我的问题是: 什么巫术巫术是为了让我的任务按预期工作而做的事情?

I am assuming, you meant task timeout as in celery's time-limit or soft-time-limit. 我假设,你的意思是任务超时,如芹菜的时间限制或软时限。 If it means requests library's timeout period then following answer does not apply. 如果它意味着请求库的超时时间,那么以下答案不适用。

If you are using eventlet as processpool then that patching has simply made your requests library behave as it is suppose to be behaving in a non-blocking execution environment. 如果您使用eventlet作为processpool,那么该修补只会使您的请求库表现得像在非阻塞执行环境中表现一样。 If you are using prefork as pocesspool, then it could be that you are not using the response from the requests.post call. 如果您使用prefork作为pocesspool,那么可能是您没有使用requests.post调用的响应。 In that case, the eventlet patching simply made your requests library non-blocking. 在这种情况下,eventlet修补只会使您的请求库无阻塞。 Since it doesn't block anymore, your task can move on and hence you don't see the task timeout, regardless of the response/timeout happening on requests library level 由于它不再阻塞,您的任务可以继续,因此您不会看到任务超时,无论请求库级别发生响应/超时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM