twisted/twisted — pull request #8 by asherf (2014-03-25 05:42:18+00:00)
Title: fix race condition in HTTPConnectionPool

a race condition occurs between HTTPConnectionPool getConnection and _putConnection

_putConnection adds a connection to the connection list (self._connections[key].append)
before adding the connection to the _timeouts dict
calling callLater will eventually trigger a system call which will cause the GIL to be released and will allow for a context switch to occur.
if in that point in time getConnection is called, it will pop the connections from the _connections[key] list and then try to access that connection on the _timeouts dict and will fail with a KeyError since it wasn't added to that dict yet.