python - Seeing ClosedPoolError when using urllib3.PoolManager -
when using urllib3.poolmanager (python 2.7, urllib3 version: 1.21) encountered closedpoolerror exceptions. after reading code i'm inclined believe expected since connection object returned may have been evicted pool's cache time used.
i have reproduced error following script:
#!/bin/bash set -ex test_dir=/tmp/urllib3_bug mkdir -p $test_dir cd $test_dir virtualenv .virtualenv . .virtualenv/bin/activate pip install urllib3==1.21 # starts 3 threads pool size = 2 echo 'from urllib3 import poolmanager import threading threading import thread pool_manager = poolmanager(num_pools=2) def start(url): print "getting", url, "on", threading.current_thread().ident return pool_manager.urlopen("get", url) thread1 = thread(target=start, args=["http://localhost:9998"]) thread2 = thread(target=start, args=["http://localhost:9999"]) thread3 = thread(target=start, args=["http://localhost:10000"]) thread1.start() import time time.sleep(1) thread2.start() thread3.start() ' > start.py # simulates preemption sleeping thread echo '303a304,308 > import time > import threading > print "simulating preemption on", threading.current_thread().ident > time.sleep(3) > print "waking on", threading.current_thread().ident' | patch $test_dir/.virtualenv/local/lib/python2.7/site-packages/urllib3/poolmanager.py - rm -f $test_dir/.virtualenv/local/lib/python2.7/site-packages/urllib3/poolmanager.pyc python start.py
i create pool of size 2, run 3 threads, each of connecting different url. first thread should encounter closedpoolerror.
(the patch inserts sleep() reliably reproduce preemption on first thread).
Comments
Post a Comment