summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-06 01:35:01 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-06 01:35:01 (GMT)
commit997980fe13ae7952665da56b122aeff9ea8fa6df (patch)
tree3b4f14732c6b3c61210685267a83523cb6b665d5 /Lib
parent97a5bad496bab7bc6e5109d10dee22bd61bb89ed (diff)
downloadcpython-997980fe13ae7952665da56b122aeff9ea8fa6df.zip
cpython-997980fe13ae7952665da56b122aeff9ea8fa6df.tar.gz
cpython-997980fe13ae7952665da56b122aeff9ea8fa6df.tar.bz2
Merged revisions 86229 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86229 | alexander.belopolsky | 2010-11-05 21:31:16 -0400 (Fri, 05 Nov 2010) | 1 line Issue #10330: trace module can now be used with python built without threads. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/trace.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/trace.py b/Lib/trace.py
index 5a77662..c01935f 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -53,7 +53,6 @@ import linecache
import os
import re
import sys
-import threading
import time
import token
import tokenize
@@ -62,6 +61,22 @@ import gc
import dis
import pickle
+try:
+ import threading
+except ImportError:
+ _settrace = sys.settrace
+
+ def _unsettrace():
+ sys.settrace(None)
+else:
+ def _settrace(func):
+ threading.settrace(func)
+ sys.settrace(func)
+
+ def _unsettrace():
+ sys.settrace(None)
+ threading.settrace(None)
+
def usage(outfile):
outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
@@ -500,14 +515,12 @@ class Trace:
if globals is None: globals = {}
if locals is None: locals = {}
if not self.donothing:
- threading.settrace(self.globaltrace)
- sys.settrace(self.globaltrace)
+ _settrace(self.globaltrace)
try:
exec(cmd, globals, locals)
finally:
if not self.donothing:
- sys.settrace(None)
- threading.settrace(None)
+ _unsettrace()
def runfunc(self, func, *args, **kw):
result = None