Skip to content

Change in profiler behaviour in CPython 3.10 #256

Closed
@joerick

Description

@joerick

Hello there! I noticed something in the unit tests for pyinstrument while adding CPython 3.10. Here's a script:

import greenlet
import sys

def greenlet_profiler():
    def dummy_profiler(frame, what, arg):
        if what == 'call':
            print(frame)
        if what == 'c_call':
            print(arg)

    sys.setprofile(dummy_profiler)

    def x():
        pass

    x()
    greenlet.greenlet(x).switch()

    sys.setprofile(None)

if __name__ == '__main__':
    greenlet_profiler()

If you run this code on Python 3.9, you get this:

$ env/bin/python3.9 private/greenlet_test.py
<frame at 0x7faf0d535c50, file '/Users/joerick/Projects/pyinstrument/private/greenlet_test.py', line 41, code x>
<built-in method switch of greenlet.greenlet object at 0x1095569e0>
<frame at 0x7faf0d535c50, file '/Users/joerick/Projects/pyinstrument/private/greenlet_test.py', line 41, code x>
<built-in function setprofile>

On CPython 3.10.0rc1, this is the output:

$ python private/greenlet_test.py      
<frame at 0x10dff7240, file '/Users/joerick/Projects/pyinstrument/private/greenlet_test.py', line 41, code x>
<built-in method switch of greenlet.greenlet object at 0x10e179d20>
<built-in function setprofile>

What's interesting is that on 3.10, a profiler that's started outside the greenlet doesn't get to 'see' inside the greenlet that it switches to. It sees only the greenlet.switch. That's a change from 3.9 and before.

I was wondering if this was an expected change? It's not necessarily an issue per-se, pyinstrument doesn't officially support greenlet anyway, so I'm not complaining, just curious if this change in behaviour is likely to be permanent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions