This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sys.setprofile bug
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AliyevH
Priority: normal Keywords:

Created on 2021-07-23 23:31 by AliyevH, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg398102 - (view) Author: Hasan (AliyevH) * Date: 2021-07-23 23:31
1. If we try to import modules except os or sys, we will get such events. 

2. If we access frame.f_locals.items() and frame.f_code.replace() inside tracefunc, function execution shows events and stops, but if access other frame.f_locals.* it begins to call and look all files in python directory

import sys

def tracefunc(frame, event, arg):
    if event == "call":        
        print('frame.f_locals.items: ->', frame.f_locals.items())
    return tracefunc

sys.setprofile(tracefunc)


def test_sum(x: int, y: int):
    return x + y

test_sum(10, 20)

import asyncio

-------------

event: -> call
frame.f_locals.items: -> dict_items([('x', 10), ('y', 20)])
event: -> return
event: -> call
frame.f_locals.items: -> dict_items([('name', 'asyncio'), ('import_', <built-in function __import__>)])
event: -> call
frame.f_locals.items: -> dict_items([('self', <_frozen_importlib._ModuleLockManager object at 0x10ae2a3f0>), ('name', 'asyncio')])
event: -> return
event: -> call
frame.f_locals.items: -> dict_items([('self', <_frozen_importlib._ModuleLockManager object at 0x10ae2a3f0>)])
event: -> call
frame.f_locals.items: -> dict_items([('name', 'asyncio')])
event: -> c_call
event: -> c_return
event: -> call
frame.f_locals.items: -> Traceback (most recent call last):
  File "/Users/hasanaliyev/Documents/programming/github/test/debugger/notwork.py", line 38, in <module>
    import asyncio
    ^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1024, in _find_and_load
  File "<frozen importlib._bootstrap>", line 170, in __enter__
  File "<frozen importlib._bootstrap>", line 196, in _get_module_lock
  File "<frozen importlib._bootstrap>", line 71, in __init__
  File "/Users/hasanaliyev/Documents/programming/github/test/debugger/notwork.py", line 24, in tracefunc
    print('frame.f_locals.items: ->', frame.f_locals.items())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 139, in __repr__
AttributeError: '_ModuleLock' object has no attribute 'name'
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88892
2021-07-23 23:31:42AliyevHsettype: behavior
2021-07-23 23:31:28AliyevHcreate