Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: improve python trace user experience #1891

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yihong0618
Copy link
Contributor

Add a simple way to support trace python file without shebang and be an executable file.

Fixed: #1890

with this path we can trace python file just like

g.py like

import sys
import urllib.request

def open_file(name):
    try:
        return open(name)
    except:
        return urllib.request.urlopen(name)

def count_word(file_obj, word):
    n = 0
    content = str(file_obj.read())
    for ln in content.split('\n'):
        n += ln.count(word)
    return n

if __name__ == '__main__':
    url = 'https://github.com/namhyung/uftrace'
    word = 'uftrace'
    if len(sys.argv) > 1:
        url = sys.argv[1]
    if len(sys.argv) > 2:
        word = sys.argv[2]

    f = open_file(url)
    n = count_word(f, word)
    print(n)

then

uftrace g.py

Add a simple way to support trace python file without shebang and
be an executable file.

Fixed: namhyung#1890
Signed-off-by: Yi Hong <zouzou0208@gmail.com>
@yskelg
Copy link
Contributor

yskelg commented Aug 14, 2024

Hi, @yihong0618,

I agree that it's convenient, but we need to consider this feature carefully.
We’ve had similar discussions before. For instance, let's assume there's an access control feature like SE Linuxor App Armor enabled.

If we allow the use of /bin/uftrace but not /bin/python3 in specific user, there's a corner case where uftrace could execute a Python script without a shebang.

Yes, you could still run the script with python g.py, but that would be specific user to allowed to using python executable.

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.

feat: improve python trace user experience.
2 participants