shotgunsoftware/python-api — pull request #27 by mikeboers (2012-11-19 21:33:53+00:00)
Title: Create one connection per thread

This patch uses thread-locals to create a connection for every thread. This allows for multiple requests to not block each other, and in extreme cases to not segfault the Python interpreter (since something in the use of zlib on OS X with Python2.6 is not thread-safe).

This is not necessarily a clean patch since the semantics surrounding closing the connection have changed; in this patch the `close()` method will only close the connection on the active thread, which is enough for the use of error handling.

With this patch my system has moved from not being able to complete 4 concurrent requests (due to timeouts) to nearly linear increases with respect to number of threads.