2
2
Debug Toolbar middleware
3
3
"""
4
4
import imp
5
- import thread
5
+ import threading
6
6
7
7
from django .conf import settings
8
8
from django .http import HttpResponseRedirect
14
14
from debug_toolbar .toolbar .loader import DebugToolbar
15
15
16
16
_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
17
18
18
19
19
20
def replace_insensitive (string , target , replacement ):
@@ -38,7 +39,7 @@ class DebugToolbarMiddleware(object):
38
39
39
40
@classmethod
40
41
def get_current (cls ):
41
- return cls .debug_toolbars .get (thread . get_ident () )
42
+ return cls .debug_toolbars .get (threading . currentThread (). ident )
42
43
43
44
def __init__ (self ):
44
45
self ._urlconfs = {}
@@ -98,11 +99,11 @@ def process_request(self, request):
98
99
toolbar = DebugToolbar (request )
99
100
for panel in toolbar .panels :
100
101
panel .process_request (request )
101
- self .__class__ .debug_toolbars [thread . get_ident () ] = toolbar
102
+ self .__class__ .debug_toolbars [threading . currentThread (). ident ] = toolbar
102
103
103
104
def process_view (self , request , view_func , view_args , view_kwargs ):
104
105
__traceback_hide__ = True
105
- toolbar = self .__class__ .debug_toolbars .get (thread . get_ident () )
106
+ toolbar = self .__class__ .debug_toolbars .get (threading . currentThread (). ident )
106
107
if not toolbar :
107
108
return
108
109
result = None
@@ -114,7 +115,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
114
115
115
116
def process_response (self , request , response ):
116
117
__traceback_hide__ = True
117
- ident = thread . get_ident ()
118
+ ident = threading . currentThread (). ident
118
119
toolbar = self .__class__ .debug_toolbars .get (ident )
119
120
if not toolbar or request .is_ajax ():
120
121
return response
0 commit comments