Skip to content

Conversation

@TTsangSC
Copy link

@TTsangSC TTsangSC commented Aug 3, 2025

Changes

  • Refactored the calls to sys.monitoring.free_tool_id() in line_profiler/_line_profiler.pyx because it has gained side effects in Python 3.14
  • Added code (and corresponding test) to copy existing code-object-local events over when overwriting the .__code__ of functions

Caveats

This does result in the active tool at sys.monitoring.PROFILER_ID no longer being overwritten with 'line_profiler' if there is an existing profiling tool. But it doesn't impact how LineProfiler functions and it's probably better this way.

line_profiler/_line_profiler.pyx::_SysMonitoringState.register()
    Updated implementation because of side effects of
    `sys.monitoring.free_tool_id()` in Python 3.14.0a1+
line_profiler/_line_profiler.pyx
    _code_replace()
        Now copying the `sys.monitoring` events of the old code object
        over
    _SysMonitoringState
        register()
            - Rolled back changes since the last commit;
              no longer double-setting the callbacks
            - No longer calling `sys.monitoring.free_tool_id()` at all
              to avoid unsetting local events
            - No longer overwriting the tool name with `'line_profiler'`
              if an existing tool is already using
              `sys.monitoring.PROFILER_ID`
        deregister()
            Updated implementation to avoid calling
            `sys.monitoring.free_tool_id()`
Copy link
Owner

@Erotemic Erotemic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nitpicks, but otherwise looks good.

@Erotemic Erotemic merged commit f558ef8 into Erotemic:update-ci-for-314 Aug 3, 2025
@TTsangSC
Copy link
Author

TTsangSC commented Aug 3, 2025

Ah, just got to those changes but seems like you've already patched those in. Thanks for the review!

@TTsangSC TTsangSC deleted the 314-sysmon-fixes branch August 3, 2025 19:59
Erotemic pushed a commit that referenced this pull request Aug 3, 2025
@Erotemic
Copy link
Owner

Erotemic commented Aug 4, 2025

I try to not ask contributors to solve nitpicks that are easy for me to make as a suggestion and then commit myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants