[Python-checkins] r86229 - python/branches/py3k/Lib/trace.py
alexander.belopolsky
python-checkins at python.org
Sat Nov 6 02:31:16 CET 2010
Author: alexander.belopolsky
Date: Sat Nov 6 02:31:16 2010
New Revision: 86229
Log:
Issue #10330: trace module can now be used with python built without threads.
Modified:
python/branches/py3k/Lib/trace.py
Modified: python/branches/py3k/Lib/trace.py
==============================================================================
--- python/branches/py3k/Lib/trace.py (original)
+++ python/branches/py3k/Lib/trace.py Sat Nov 6 02:31:16 2010
@@ -53,7 +53,6 @@
import os
import re
import sys
-import threading
import time
import token
import tokenize
@@ -62,6 +61,22 @@
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 @@
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
More information about the Python-checkins
mailing list