IronLanguages / IronLanguages/ironpython3

Stack frames missing in other threads when settrace used.

Open
#2,072 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.8k
Forks
316
Avg merge
1d 9h
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run repro_issue.py with the tracer enabled and compare the result with the CPython output. Start with the stack-frame assumptions behind sys._getframe in lib/typing.py and the recursive checks in lib/abc.py; done means the threaded isinstance check succeeds under settrace without the ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.