Issue #16098:  Update heapq.nsmallest to use the same algorithm as nlargest.

This removes the dependency on bisect and it bring the pure Python code
in-sync with the C code.
Add test for RLock in the lru_cache().
merge
Fix other re-entrancy nits for the lru_cache.

Keep references for oldkey and oldvalue so they can't
trigger a __del__ method to reenter our thread.

Move the cache[key]=link step to the end, after the link
data is in a consistent state.

Under exotic circumstances, the cache[key]=link step could
trigger reentrancy (i.e. the key would have to have a hash
exactly equal to that for another key in the cache and the
key would need a __eq__ method that makes a reentrant call
our cached function).
merge
Another nit.
Merge
#17346: make sure pickle tests are run against all protocols.  Initial patch by Marius Gedminas.
#17346: merge with 3.2.
#17346: merge with 3.3.
fix possible setdefault refleak (closes #17328)
merge 3.3 (#17328)
Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is being resized concurrently.
Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is being resized concurrently.
Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when the list is being resized concurrently.