Type checks in other threads were failing with ValueError: call stack not deep enough when I tried to trace my main thread. It looks like settrace causes stack to be lost. I do not see the same in CPython.
Repro
import argparse
import typing
import collections.abc
import sys
import threading
# This reproduction script demonstrates a "ValueError: call stack is not deep enough"
# in IronPython 3 when performing isinstance/issubclass checks against ABCs
# that have parameterized generics as subclasses.
class NotAMapping:
pass
def tracer(frame, event, arg):
return tracer
def do_check():
print("Attempting isinstance check...")
try:
isinstance(NotAMapping(), collections.abc.Mapping)
print("Success.")
except Exception as e:
print("\nCaught error: {}: {}".format(type(e).__name__, e))
import traceback
traceback.print_exc()
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-t', '--trace', action='store_true', help='Set tracer.')
args = parser.parse_args()
print(sys.version)
if args.trace:
print("Enabling trace...")
sys.settrace(tracer)
t = threading.Thread(target=do_check)
t.start()
t.join()
CPython 3.4
$ python repro_issue.py -t
3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)]
Enabling trace...
Attempting isinstance check...
Success.
IronPython 3.4
$ ipy.exe repro_issue.py -t
3.4.2 (3.4.2.1000)
[.NETFramework,Version=v4.6.2 on .NET Framework 4.8.9324.0 (64-bit)]
Enabling trace...
Attempting isinstance check...
Caught error: ValueError: call stack is not deep enough
Traceback (most recent call last):
File "repro_issue.py", line 20, in do_check
isinstance(NotAMapping(), collections.abc.Mapping)
File "C:\Program Files\IronPython 3.4\lib\abc.py", line 191, in __instancecheck__
return cls.__subclasscheck__(subclass)
File "C:\Program Files\IronPython 3.4\lib\abc.py", line 226, in __subclasscheck__
if issubclass(subclass, scls):
File "C:\Program Files\IronPython 3.4\lib\abc.py", line 226, in __subclasscheck__
if issubclass(subclass, scls):
File "C:\Program Files\IronPython 3.4\lib\typing.py", line 1158, in __subclasscheck__
return super().__subclasscheck__(cls)
File "C:\Program Files\IronPython 3.4\lib\abc.py", line 226, in __subclasscheck__
if issubclass(subclass, scls):
File "C:\Program Files\IronPython 3.4\lib\typing.py", line 1151, in __subclasscheck__
if sys._getframe(1).f_globals['__name__'] not in ['abc', 'functools']:
ValueError: call stack is not deep enough
Type checks in other threads were failing with
ValueError: call stack not deep enoughwhen I tried to trace my main thread. It looks likesettracecauses stack to be lost. I do not see the same in CPython.Repro
CPython 3.4
IronPython 3.4