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 REPL stacktrace #56

Open
khaven opened this issue Jan 10, 2024 · 6 comments
Open

Python REPL stacktrace #56

khaven opened this issue Jan 10, 2024 · 6 comments

Comments

@khaven
Copy link

khaven commented Jan 10, 2024

Hi,
Is it possible to get full stacktrace of exception in python REPL flask example code. Right now the code is like this

`class PythonRunner:
__globals = {}
__locals = {}

def run(self, code):
    f = StringIO()
    with redirect_stdout(f):
        exec(code, self.__globals, self.__locals)
    return f.getvalue()` 

I've managed to get the full stacktrace but is it possible to exclude the info about the main.py file in the stacktrace?
Capture
I want the stacktrace to look like the code was run from a file on a command line.

@khaven
Copy link
Author

khaven commented Jan 10, 2024

This code works well on normal compiler but doesn't work on android.

`import subprocess
import traceback
import sys

code = "import numpy as np\nprint(1/0)" # Example code with a division by zero error

python_executable = sys.executable # Get the path to the current Python interpreter

try:
result = subprocess.run(
[python_executable, "-c", code],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)
except subprocess.CalledProcessError as e:
print(e.stderr)`

It shows "[Errno 13] Permission denied:"

@FeodorFitsner
Copy link
Contributor

subprocess won't work on Android. Mobiles don't allow spawning new processes.

@khaven
Copy link
Author

khaven commented Jan 10, 2024

Is it possible to directly run a file and get it's stacktrace? I see a function "runProgram" is available but is it possible to get the
stacktrace from it?

@FeodorFitsner
Copy link
Contributor

Working on that: flet-dev/flet#2352
It's #1 priority right now.

@khaven
Copy link
Author

khaven commented Jan 10, 2024

Thank you! :)

@khaven
Copy link
Author

khaven commented Jan 16, 2024

Hi,
I'm testing the new ^0.7.0 version. I'm trying to get the stacktrace from a file. This file was created runtime and not exists in asset.
But i'm getting a message instead of a stacktrace. Is it supposed to work like that?

Capture
Capture1

and if i put print("Hello") in the file and no errors then it returning empty string. Am i doing something wrong here?

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

No branches or pull requests

2 participants