diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-06 01:38:48 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-06 01:38:48 (GMT) |
commit | 860c05d9f7fe7da7e9633c7aa24a9dbc07b048b7 (patch) | |
tree | c0baf8255256ad1a7e0a58e2c26224bb4935e365 | |
parent | 0c6d438a173f387b07c3d8ac615d30536d496411 (diff) | |
download | cpython-860c05d9f7fe7da7e9633c7aa24a9dbc07b048b7.zip cpython-860c05d9f7fe7da7e9633c7aa24a9dbc07b048b7.tar.gz cpython-860c05d9f7fe7da7e9633c7aa24a9dbc07b048b7.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.
........
-rw-r--r-- | Lib/trace.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 12e1b49..97491db 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -52,7 +52,6 @@ import linecache import os import re import sys -import threading import time import token import tokenize @@ -65,6 +64,22 @@ try: except ImportError: 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] @@ -501,14 +516,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 in globals, locals finally: if not self.donothing: - sys.settrace(None) - threading.settrace(None) + _unsettrace() def runfunc(self, func, *args, **kw): result = None |