首页 > 解决方案 > 收到消息后立即发送 201 响应,然后将其保存到 DB - Python 3.6

问题描述

我们有一个从设备接收数据的 python (3.6) 脚本。

我们需要在收到消息后立即发送 201 响应,然后再将其保存到 DB。

如何执行返回 201 并保持脚本运行?

    def main(args):
        '''
        Main function - runs every time the function is executed.
        '''
        print("HELLO")
        ## need to send a return 201 right now and continue running the 
        ## code to save data into DB
        ...
        args = {"temp1":{"timestamp": posix_dt, "value": store_details['value']}}
        req = update_device(device, args, token)
        return {"status": "Ok", "result": req.json()}
        ## saved to DB

非常感谢您的帮助。最好的,

标签: pythonpostrequest

解决方案


推荐阅读