Skip to content

Commit

Permalink
Use python threading module instead of the python3 deprecated thread …
Browse files Browse the repository at this point in the history
…module. Fix this threading related bug - Exception AttributeError: AttributeError("_DummyThread object has no attribute _Thread__block",) in <module threading from
  • Loading branch information
calvinchengx committed Nov 3, 2012
1 parent aeb45f2 commit 9b1fbf2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions debug_toolbar/middleware.py
Expand Up @@ -2,7 +2,7 @@
Debug Toolbar middleware
"""
import imp
import thread
import threading

from django.conf import settings
from django.http import HttpResponseRedirect
Expand All @@ -14,6 +14,7 @@
from debug_toolbar.toolbar.loader import DebugToolbar

_HTML_TYPES = ('text/html', 'application/xhtml+xml')
threading._DummyThread._Thread__stop = lambda x: 1 # Handles python threading module bug - http://bugs.python.org/issue14308


def replace_insensitive(string, target, replacement):
Expand All @@ -38,7 +39,7 @@ class DebugToolbarMiddleware(object):

@classmethod
def get_current(cls):
return cls.debug_toolbars.get(thread.get_ident())
return cls.debug_toolbars.get(threading.currentThread())

def __init__(self):
self._urlconfs = {}
Expand Down Expand Up @@ -98,11 +99,11 @@ def process_request(self, request):
toolbar = DebugToolbar(request)
for panel in toolbar.panels:
panel.process_request(request)
self.__class__.debug_toolbars[thread.get_ident()] = toolbar
self.__class__.debug_toolbars[threading.currentThread()] = toolbar

def process_view(self, request, view_func, view_args, view_kwargs):
__traceback_hide__ = True
toolbar = self.__class__.debug_toolbars.get(thread.get_ident())
toolbar = self.__class__.debug_toolbars.get(threading.currentThread())
if not toolbar:
return
result = None
Expand All @@ -114,7 +115,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):

def process_response(self, request, response):
__traceback_hide__ = True
ident = thread.get_ident()
ident = threading.currentThread()
toolbar = self.__class__.debug_toolbars.get(ident)
if not toolbar or request.is_ajax():
return response
Expand Down

0 comments on commit 9b1fbf2

Please sign in to comment.