Flask grequests 钩子中的附加参数

Additional arguments in Flask grequests hook

我在使用钩子将附加参数传递给 grequests 时遇到问题,它在独立应用程序(非烧瓶)中工作,但它不适用于烧瓶(烧瓶集成服务器)这是我的代码片段。

self.async_list = []
for url in self.urls:
   self.action_item = grequests.get(url, hooks = {'response' : [self.hook_factory(test='new_folder')]}, proxies={ 'http': 'proxy url'},timeout=20)
   self.async_list.append(self.action_item)

grequests.map(self.async_list)

def hook_factory(self, test, *factory_args, **factory_kwargs):
        print (test + "In start of hook factory") #this worked and I see test value is printing as new_folder
        def do_something(response, *args, **kwargs):
            print (test + "In do something") #This is not working hence I was not able to save this response to a newly created folder. 

            self.file_name = "str(test)+"/"
            print ("file name is " + self.file_name)
            with open(REL_PATH + self.file_name, 'wb') as f:    
                    f.write(response.content)
            return None
        return do_something

我在这里遗漏了什么吗?

试图回答我自己的问题,经过进一步分析,上面的代码没有任何问题,但出于某种原因,我没有得到 request_ctx_stack.top 中的会话数据。但是在我的 h_request_ctx_stack._local 中可以获得相同的会话数据,不知道原因。但是对于这个挂钩,我能够从 h_request_ctx_stack._local 而不是 _request_ctx_stack.top 获取我的数据。在我做出更改后,可以毫无问题地执行相同的挂钩。