【发布时间】:2017-02-08 18:22:14
【问题描述】:
我想通过多处理在多个 python 进程之间共享稍微修改过的 requests.Session 版本,但奇怪的事情发生在我身上。通过 Queue 和 Manager,我得到的 requests.Session 对象都被删除了我的修改。
s = requests.Session()
s._my_custom_field = "test"
q = multiprocessing.Queue()
q.put(s)
s_from_queue = q.get(s)
s_from_queue._my_custom_field
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Session' object has no attribute '_my_custom_field'
同样的事情发生在经理身上。任何想法为什么会发生这种情况以及我应该如何在进程之间共享 requests.Session?谢谢。
【问题讨论】:
标签: python python-requests python-multiprocessing