Using session object in a multiprocess pool 

Hi,

I am trying to run parallel requests to server. And my understanding is that it is only possible by having multiple connections created to the server. And I think somehow the Session object is doing that -> automatically creating multiple connections to the server from a single session object or it could be that a new scope of session object is created when a new process is forked and hence, new connection is created. 

Now, I want to send a bulk of requests to the process pool such that the requests are streamlined in to the existing connections.
ie., Let's say if I have 50 requests and processpool of 20 and using map function, I can submit the 50 requests in bulk to the process pool. Internally, it the splits the 50 requests to 20 sets based on some hash value I think and they are submitted to each process in the pool.  

Issue is that I expected a maximum of 20 connections will be created and which will stay alive and handles all the existing requests. However, I see the connections are being recycled and I couldn't find a pattern.

However, I could see the issue only when I give the process pool a value higher than 10 and if I give a value less than 10, the connections doesn't recycle.

I have tried disabling the garbage collector import gc; gc.disable() and still connections are recycled.

```
#!/usr/bin/env python3
import time
import requests
from multiprocessing.dummy import Pool as ProcessPool, current_process as processpool_process

def get_list_of_ids():
     some_calls()
     return(id_list)

def check_ids(id):
     url = f"https://myserver.com/check/{ id }"
     json_op = s.get(url,verify=False).json()
     value = json_op['id']
     print(str(value) + '-' + str(processpool_process()) + str(id(s)))

def main():
     pool = ProcessPool(processes=20)
     while True:
        pool.map(check_ids, get_list_of_ids())
        print("Let's wait for 10 seconds")
        time.sleep(10)

if __name__ == "__main__":
    s = requests.Session()
    s.headers.update = {
      'Accept': 'application/json'
    }
    main()
```
Output Example:
```
4-<DummyProcess(Thread-2, started daemon 140209222559488)>140209446508360
5-<DummyProcess(Thread-5, started daemon 140209123481344)>140209446508360
7-<DummyProcess(Thread-6, started daemon 140209115088640)>140209446508360
2-<DummyProcess(Thread-11, started daemon 140208527894272)>140209446508360
None-<DummyProcess(Thread-1, started daemon 140209230952192)>140209446508360
10-<DummyProcess(Thread-4, started daemon 140209131874048)>140209446508360
12-<DummyProcess(Thread-7, started daemon 140209106695936)>140209446508360
8-<DummyProcess(Thread-3, started daemon 140209140266752)>140209446508360
6-<DummyProcess(Thread-12, started daemon 140208519501568)>140209446508360
3-<DummyProcess(Thread-13, started daemon 140208511108864)>140209446508360
11-<DummyProcess(Thread-10, started daemon 140208536286976)>140209446508360
9-<DummyProcess(Thread-9, started daemon 140209089910528)>140209446508360
1-<DummyProcess(Thread-8, started daemon 140209098303232)>140209446508360
Let's wait for 10 seconds
None-<DummyProcess(Thread-14, started daemon 140208502716160)>140209446508360
3-<DummyProcess(Thread-20, started daemon 140208108455680)>140209446508360
1-<DummyProcess(Thread-19, started daemon 140208116848384)>140209446508360
7-<DummyProcess(Thread-17, started daemon 140208133633792)>140209446508360
6-<DummyProcess(Thread-6, started daemon 140209115088640)>140209446508360
4-<DummyProcess(Thread-4, started daemon 140209131874048)>140209446508360
9-<DummyProcess(Thread-16, started daemon 140208485930752)>140209446508360
5-<DummyProcess(Thread-15, started daemon 140208494323456)>140209446508360
2-<DummyProcess(Thread-2, started daemon 140209222559488)>140209446508360
8-<DummyProcess(Thread-18, started daemon 140208125241088)>140209446508360
11-<DummyProcess(Thread-1, started daemon 140209230952192)>140209446508360
10-<DummyProcess(Thread-11, started daemon 140208527894272)>140209446508360
12-<DummyProcess(Thread-5, started daemon 140209123481344)>140209446508360
Let's wait for 10 seconds
None-<DummyProcess(Thread-3, started daemon 140209140266752)>140209446508360
2-<DummyProcess(Thread-10, started daemon 140208536286976)>140209446508360
1-<DummyProcess(Thread-12, started daemon 140208519501568)>140209446508360
4-<DummyProcess(Thread-9, started daemon 140209089910528)>140209446508360
5-<DummyProcess(Thread-14, started daemon 140208502716160)>140209446508360
9-<DummyProcess(Thread-6, started daemon 140209115088640)>140209446508360
8-<DummyProcess(Thread-16, started daemon 140208485930752)>140209446508360
7-<DummyProcess(Thread-4, started daemon 140209131874048)>140209446508360
3-<DummyProcess(Thread-20, started daemon 140208108455680)>140209446508360
6-<DummyProcess(Thread-8, started daemon 140209098303232)>140209446508360
12-<DummyProcess(Thread-13, started daemon 140208511108864)>140209446508360
10-<DummyProcess(Thread-7, started daemon 140209106695936)>140209446508360
11-<DummyProcess(Thread-19, started daemon 140208116848384)>140209446508360
Let's wait for 10 seconds
.
.
```
Is it the correct way of creating batch requests using session object to a multi process pool and at the same time have optimal use of resources?


> Issue is that I expected a maximum of 20 connections will be created and which will stay alive and handles all the existing requests. However, I see the connections are being recycled and I couldn't find a pattern.

There are so many potential problems happening here, not the least of which being a fundamental misunderstanding of how server connections work in real life and how much control a session has over them. Your issue description has barely enough detail to elaborate on these, but I'll try.

Most reasonable, moderately resource-conscious servers will never let connections sit open for over  10 seconds, let alone 20 such connections from one client. The session can not prevent the server from closing those connections and can only try its best to reuse connections to the server while able, but if the server closes the connection there's nothing the session can do to stop it.

On top of that, the `multiprocessing` library has many different ways of forking different threads. In your example, you're using [threading](https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.dummy) (via `multiprocessing.dummy` which is ideal for lots of IO but not for actual computation in parallel (which could be contributing to your issue but I wouldn't know because there's so much likely missing from your example). So your computation here could be enough to slow you down and let the server close the connection. Further, one shared session will not work with all of the ways `multiprocessing` forks. You cannot share the connections or connection pools for each of those methods and I will not illuminate which of those are which as they're well documented by the `multiprocessing` library.

Finally, your output here does not actually demonstrate the problem you're describing. The session instance seems to be the same across all of the threads so I don't know how your reproduction case or its output is intended to convey that you're connections are being allowed to close and then being re-opened.

This, not being a bug with Requests, I'm closing this issue. If you have further support needs, please use [StackOverflow](https://stackoverflow.com)