22Debug Toolbar middleware
33"""
44import imp
5- import thread
5+ import threading
66
77from django .conf import settings
88from django .http import HttpResponseRedirect
1414from 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
1920def 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