Closed david-fortini closed 2 months ago
Great suggestion, I like this issue!
We can try to catch the Exceptions when exiting with CTRL+C. It will be much cleaner, yes
Hi @trgiangdo @FlorianJacta, I want to work on this issue, could you please assign it to me?
Hi @trgiangdo @david-fortini , could you please guide that how can I reproduce this issue?
Also, @trgiango, could you please guide that for the catching the Exceptions, I've to make changes in the taipy/cli/
dir, am I right?
Hi @yaten2302 , so basically just launch any app and close with CTRL+C.
Issue Description
Right now, every time I close taipy using CTRL+C, a long traceback gets printed. What is the proper way to close the app without having this?
Hi @yaten2302 , so basically just launch any app and close with CTRL+C.
Issue Description
Right now, every time I close taipy using CTRL+C, a long traceback gets printed. What is the proper way to close the app without having this?
Got it @david-fortini 👍 @trgiangdo, could you please guide that in which dir or file the taipy cli is located, like where the catching and all is done?
If you launch a Taipy app using taipy run ...
command, then the file that handle the app execution is taipy/_cli/_run_cli.py
.
However, if launching Taipy app using python ...
, I'm not sure if there is anything we can do on Taipy side.
Got it @trgiangdo 👍, so, like, in the file - taipy/_cli/_run_cli.py
, I've to make changes in the handle_command(cls)
function? I was just checking, it's given like this (the handle_command func):
def handle_command(cls):
args, _ = _TaipyParser._parser.parse_known_args()
if getattr(args, "which", None) != "run":
return
all_args = sys.argv[3:] # First 3 args are always (1) Python executable, (2) run, (3) Python file
external_args = []
try:
external_args_index = all_args.index("external-args")
except ValueError:
pass
else:
external_args.extend(all_args[external_args_index + 1 :])
all_args = all_args[:external_args_index]
taipy_args = [f"--taipy-{arg[2:]}" if arg.startswith("--") else arg for arg in all_args]
subprocess.run(
[sys.executable, args.application_main_file, *(external_args + taipy_args)],
stdout=sys.stdout,
stderr=sys.stdout,
)
sys.exit(0)
So, will it help by removing the stdout=sys.stdout
in the subprocess.run(...)
, because ig on executing the subprocess.run(...)
, the stdout
is only which is getting logged to the cli?
If removing stdout, all errors will be lost right? I don't think we want that
Yes @trgiangdo , we don't want that. I thought that the errors are logged from the stderr=sys.stdout
? Is it like that? Like, I was just reading the doc of sys
, it's showing that stderr
is used to capture any exception that occurs, is it like that or by removing the stdout
, it'll remove all the errors as well?
You can test it out. Either way, the behavior that we want is:
KeyboardInterrupt
exception, we will exit without showing the error of that specific exceptionYou can test it out. Either way, the behavior that we want is:
- If the application has any error, exceptions, etc, it needs to be shown in the stdout
- Except from
KeyboardInterrupt
exception, we will exit without showing the error of that specific exception
@trgiangdo, could you please guide that how can I test it? Like what command do I've to run?
You can launch any app using the taipy run ..
command as in https://docs.taipy.io/en/latest/manuals/cli/run/, then CTRL+C to see if it works or not
You can launch any app using the
taipy run ..
command as in https://docs.taipy.io/en/latest/manuals/cli/run/, then CTRL+C to see if it works or not
@trgiangdo, but by this method, will I be able to test my changes? Because, let's say that I initialized a taipy project, but then, all the dependencies installed will be those present in the official taipy repo and not mine? Is it like that or am I going wrong somewhere?
Your environment needs to have Taipy installed from your local taipy repository so that the change may take effect
Your environment needs to have Taipy installed from your local taipy repository so that the change may take effect
@trgiangdo, could you please guide that how can I install my local taipy repo into a project?
You can follow the guide for pip regular local project installation here: https://pip.pypa.io/en/stable/topics/local-project-installs/#regular-installs
Hey @trgiangdo, I tried to change the handle_command
function, but I'm having some issues, could you please guide that where am I going wrong?
Also, when I'm running this command - C:/Python312/python.exe main.py
, it's not showing any KeyboardInterrupt
error, but, when I'm running this one - taipy run main.py
, it's showing the KeyboardInterrupt
error?
Could you please guide that where am I going wrong?
I don't know about this, sorry. Apparently it's not as simple as just catching the KeyboardInterrupt
error.
We need to find a better way of doing this
Hey @trgiangdo, actually, when I'm trying to run this command - py -m pip install path/to/taipy
, it's showing this error, could you please guide how to fix this:
Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\\Python312\\Scripts\\taipy.exe' -> 'C:\\Python312\\Scripts\\taipy.exe.deleteme'
I found this stackoverflow thread that could resolve your problem: https://stackoverflow.com/questions/66322049/could-not-install-packages-due-to-an-oserror-winerror-2-no-such-file-or-direc
Hey @trgiangdo, actually I was working on this issue for a few days, I took help on some discord servers as well and what I found is that this might solve this issue?
try:
subprocess.run(
[sys.executable, args.application_main_file, *(external_args + taipy_args)],
stdout=sys.stdout,
stderr=sys.stdout,
)
except KeyboardInterrupt:
sys.exit(0)
Could you please check that if it's working for you or not, because on my side ig there's some problem with installing the project locally? If not, then maybe I'll try some other method?
I tried this approach and on my previous comment
Apparently it's not as simple as just catching the
KeyboardInterrupt
error. We need to find a better way of doing this
There are also some other errors that are raised, so the log is not really clean yet
I tried this approach and on my previous comment
Apparently it's not as simple as just catching the
KeyboardInterrupt
error. We need to find a better way of doing thisThere are also some other errors that are raised, so the log is not really clean yet
@trgiangdo is the Keyboard Interrupt error still there, like even after using the try except?
yes it's still there along side some other errors
yes it's still there along side some other errors
That's weird! @trgiangdo, maybe I'll try to ask regarding this issue in the Taipy discord server? If at this point it's difficult to fix this issue, then maybe we can put this on a hault and try fixing the other existing issues. I'll also keep checking about it how to fix this👍
This issue has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this issue, please add another comment or create a PR that links to this issue. If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. Otherwise, you will be unassigned in 14 days. For more information please refer to the contributing guidelines.
This issue has been unassigned automatically because it has been marked as "🥶Waiting for contributor" for more than 14 days with no activity.
@trgiangdo #1595 fixes this issue. Kindly have a look at the PR.
Issue Description
Right now, every time I close taipy using CTRL+C, a long traceback gets printed. What is the proper way to close the app without having this?
Screenshots or Examples (if applicable)
^C is where the interrupt happens
Proposed Solution (optional)
Either document how to shut it down gracefully or just show
shutting down server
without showing traceback.Code of Conduct