diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-06 01:31:16 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-06 01:31:16 (GMT) |
commit | 25b574138353df835c94039eecb0b9edefc1dede (patch) | |
tree | 7c0b02ccea85334b377affbf14eb8ba7f1250dca /Lib/trace.py | |
parent | ecd34cbbb8823d2ce250887d55093a909b8cb94d (diff) | |
download | cpython-25b574138353df835c94039eecb0b9edefc1dede.zip cpython-25b574138353df835c94039eecb0b9edefc1dede.tar.gz cpython-25b574138353df835c94039eecb0b9edefc1dede.tar.bz2 |
Issue #10330: trace module can now be used with python built without threads.
Diffstat (limited to 'Lib/trace.py')
-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 ec45d81..b24d193 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] @@ -491,14 +506,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 |