Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f47e84c

Browse files
committed
Merged revisions 70956 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70956 | brett.cannon | 2009-04-01 09:00:34 -0700 (Wed, 01 Apr 2009) | 5 lines The cgitb module had imports in its functions. This can cause deadlock with the import lock if called from within a thread that was triggered by an import. Partially fixes issue #1665206. ........
1 parent c748506 commit f47e84c

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

Lib/cgitb.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
1919
for you, call cgitb.handler(). The optional argument to handler() is a
2020
3-item tuple (etype, evalue, etb) just like the value of sys.exc_info().
2121
The default handler displays output as HTML.
22-
"""
23-
24-
__author__ = 'Ka-Ping Yee'
25-
26-
__version__ = '$Revision$'
2722
23+
"""
24+
import inspect
25+
import keyword
26+
import linecache
27+
import os
28+
import pydoc
2829
import sys
30+
import tempfile
31+
import time
32+
import tokenize
33+
import traceback
34+
import types
2935

3036
def reset():
3137
"""Return a string that resets the CGI and browser to a known state."""
@@ -74,7 +80,6 @@ def lookup(name, frame, locals):
7480

7581
def scanvars(reader, frame, locals):
7682
"""Scan one logical line of Python and look up values of variables used."""
77-
import tokenize, keyword
7883
vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__
7984
for ttype, token, start, end, line in tokenize.generate_tokens(reader):
8085
if ttype == tokenize.NEWLINE: break
@@ -96,8 +101,6 @@ def scanvars(reader, frame, locals):
96101

97102
def html(einfo, context=5):
98103
"""Return a nice HTML document describing a given traceback."""
99-
import os, time, traceback, linecache, inspect, pydoc
100-
101104
etype, evalue, etb = einfo
102105
if isinstance(etype, type):
103106
etype = etype.__name__
@@ -173,7 +176,6 @@ def reader(lnum=[lnum]):
173176
value = pydoc.html.repr(getattr(evalue, name))
174177
exception.append('\n<br>%s%s&nbsp;=\n%s' % (indent, name, value))
175178

176-
import traceback
177179
return head + ''.join(frames) + ''.join(exception) + '''
178180
179181
@@ -188,8 +190,6 @@ def reader(lnum=[lnum]):
188190

189191
def text(einfo, context=5):
190192
"""Return a plain text document describing a given traceback."""
191-
import os, time, traceback, linecache, inspect, pydoc
192-
193193
etype, evalue, etb = einfo
194194
if isinstance(etype, type):
195195
etype = etype.__name__
@@ -245,7 +245,6 @@ def reader(lnum=[lnum]):
245245
value = pydoc.text.repr(getattr(evalue, name))
246246
exception.append('\n%s%s = %s' % (" "*4, name, value))
247247

248-
import traceback
249248
return head + ''.join(frames) + ''.join(exception) + '''
250249
251250
The above is a description of an error in a Python program. Here is
@@ -278,7 +277,6 @@ def handle(self, info=None):
278277
try:
279278
doc = formatter(info, self.context)
280279
except: # just in case something goes wrong
281-
import traceback
282280
doc = ''.join(traceback.format_exception(*info))
283281
plain = True
284282

@@ -292,7 +290,6 @@ def handle(self, info=None):
292290
self.file.write('<p>A problem occurred in a Python script.\n')
293291

294292
if self.logdir is not None:
295-
import os, tempfile
296293
suffix = ['.txt', '.html'][self.format=="html"]
297294
(fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
298295
try:

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ Core and Builtins
286286
Library
287287
-------
288288

289+
- Issue #1665206 (partially): Move imports in cgitb to the top of the module
290+
instead of performing them in functions. Helps prevent import deadlocking in
291+
threads.
292+
289293
- Issue #2522: locale.format now checks its first argument to ensure it has
290294
been passed only one pattern, avoiding mysterious errors where it appeared
291295
that it was failing to do localization.

0 commit comments

Comments
 (0)