Issue #10330: trace module can now be used with python built without threads.
This commit is contained in:
parent
ecd34cbbb8
commit
25b5741383
23
Lib/trace.py
23
Lib/trace.py
|
@ -53,7 +53,6 @@ import linecache
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import threading
|
|
||||||
import time
|
import time
|
||||||
import token
|
import token
|
||||||
import tokenize
|
import tokenize
|
||||||
|
@ -62,6 +61,22 @@ import gc
|
||||||
import dis
|
import dis
|
||||||
import pickle
|
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):
|
def usage(outfile):
|
||||||
outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
|
outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
|
||||||
|
|
||||||
|
@ -491,14 +506,12 @@ class Trace:
|
||||||
if globals is None: globals = {}
|
if globals is None: globals = {}
|
||||||
if locals is None: locals = {}
|
if locals is None: locals = {}
|
||||||
if not self.donothing:
|
if not self.donothing:
|
||||||
threading.settrace(self.globaltrace)
|
_settrace(self.globaltrace)
|
||||||
sys.settrace(self.globaltrace)
|
|
||||||
try:
|
try:
|
||||||
exec(cmd, globals, locals)
|
exec(cmd, globals, locals)
|
||||||
finally:
|
finally:
|
||||||
if not self.donothing:
|
if not self.donothing:
|
||||||
sys.settrace(None)
|
_unsettrace()
|
||||||
threading.settrace(None)
|
|
||||||
|
|
||||||
def runfunc(self, func, *args, **kw):
|
def runfunc(self, func, *args, **kw):
|
||||||
result = None
|
result = None
|
||||||
|
|
Loading…
Reference in New Issue