From 80e879386b22aa4c3fc4ff333a75dd867e6b3417 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 8 Oct 2010 13:17:25 -0700 Subject: [PATCH] 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. --- AUTHORS | 3 ++- eventlet/tpool.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5efebc7..6dc5d6d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -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 \ No newline at end of file +* Holger Krekel, websocket example small fix +* mikepk, debugging MySQLdb/tpool issues diff --git a/eventlet/tpool.py b/eventlet/tpool.py index 553b22e..3281cbc 100644 --- a/eventlet/tpool.py +++ b/eventlet/tpool.py @@ -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()