From 87c172b64686857e318850efcbb75862cb31baf2 Mon Sep 17 00:00:00 2001 From: Krishna4907 Date: Mon, 29 Dec 2025 12:04:59 +0530 Subject: [PATCH] Docs: clarify Session safety in multi-process environments --- docs/user/advanced.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index 2ff0c7dfbf..1d0b270430 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -17,6 +17,16 @@ you're making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see `HTTP persistent connection`_). +.. warning:: + + ``requests.Session`` objects are **not safe to share across multiple processes**. + In a multi-process environment (for example, when using ``multiprocessing`` or + task queues like Celery), create a **separate Session in each process**. + + Sharing a Session across processes may lead to unexpected behavior due to + connection pooling being inherited after a process fork. + + A Session object has all the methods of the main Requests API. Let's persist some cookies across requests::