Skip to content

Commit 25ea0b4

Browse files
committed
Merge pull request #333 from calvinchengx/master
Use threading instead of thread. Resolve _DummyThread bug.
2 parents 5ae6fcc + 1a7609c commit 25ea0b4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

debug_toolbar/middleware.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Debug Toolbar middleware
33
"""
44
import imp
5-
import thread
5+
import threading
66

77
from django.conf import settings
88
from django.http import HttpResponseRedirect
@@ -14,6 +14,7 @@
1414
from debug_toolbar.toolbar.loader import DebugToolbar
1515

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

1819

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

3940
@classmethod
4041
def get_current(cls):
41-
return cls.debug_toolbars.get(thread.get_ident())
42+
return cls.debug_toolbars.get(threading.currentThread().ident)
4243

4344
def __init__(self):
4445
self._urlconfs = {}
@@ -98,11 +99,11 @@ def process_request(self, request):
9899
toolbar = DebugToolbar(request)
99100
for panel in toolbar.panels:
100101
panel.process_request(request)
101-
self.__class__.debug_toolbars[thread.get_ident()] = toolbar
102+
self.__class__.debug_toolbars[threading.currentThread().ident] = toolbar
102103

103104
def process_view(self, request, view_func, view_args, view_kwargs):
104105
__traceback_hide__ = True
105-
toolbar = self.__class__.debug_toolbars.get(thread.get_ident())
106+
toolbar = self.__class__.debug_toolbars.get(threading.currentThread().ident)
106107
if not toolbar:
107108
return
108109
result = None
@@ -114,7 +115,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
114115

115116
def process_response(self, request, response):
116117
__traceback_hide__ = True
117-
ident = thread.get_ident()
118+
ident = threading.currentThread().ident
118119
toolbar = self.__class__.debug_toolbars.get(ident)
119120
if not toolbar or request.is_ajax():
120121
return response

0 commit comments

Comments
 (0)