Fixing hang when importing a module that makes a tpooled MySQLdb connection, thanks to mikepk for getting to the bottom of this. Still needs a unit test.

This commit is contained in:
Ryan Williams
2010-10-08 13:17:25 -07:00
parent d1ef6f39e7
commit 80e879386b
2 changed files with 6 additions and 2 deletions

View File

@@ -62,4 +62,5 @@ Thanks To
* Favo Yang, twisted hub patch
* Schmir, patch that fixes readline method with chunked encoding in wsgi.py, advice on patcher
* Slide, for open-sourcing gogreen
* Holger Krekel, websocket example small fix
* Holger Krekel, websocket example small fix
* mikepk, debugging MySQLdb/tpool issues

View File

@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import imp
import os
import sys
@@ -97,8 +98,10 @@ def execute(meth,*args, **kwargs):
global _threads
setup()
# if already in tpool, don't recurse into the tpool
# also, call functions directly if we're inside an import lock, because
# if meth does any importing (sadly common), it will hang
my_thread = threading.currentThread()
if my_thread in _threads:
if my_thread in _threads or imp.lock_held():
return meth(*args, **kwargs)
cur = greenthread.getcurrent()