littlewhitecloud / TkTerminal

A terminal emulator widget written in Python using tkinter
MIT License
15 stars 2 forks source link

App freezes when running commands like `python3 filename.py` #6

Open Moosems opened 1 year ago

Moosems commented 1 year ago

When I run a Python file that uses tkinter, re-focusing the app shows that its confused as there is the rotating wheel of death.

Moosems commented 1 year ago

Actually, they're slightly different. #4 is about REPLs and how you can't give input whereas this is about if you run a command that takes a long time, the app freezes.

littlewhitecloud commented 1 year ago

Okay. I just mean the app freezes just like #4

sumeshir26 commented 1 year ago

Actually, they're slightly different. #4 is about REPLs and how you can't give input whereas this is about if you run a command that takes a long time, the app freezes.

Tkinter marks the window as not responding if the app does not respond for 5 seconds. Since the app currently freezes its process till the command finishes executing, if the command lasts 5+ secs the app freezes.

Moosems commented 1 year ago

Correct, but running any tkinter apps from the terminal will cause issues (an example).

littlewhitecloud commented 1 year ago

So, is there any way to solve this problem?

Moosems commented 1 year ago

Thats a great question. My current idea is this:

Right now, the way the terminal works is to run the command on <Return>. The running of this command takes place in an event which must complete before anything else can happen. To fix this, we could possibly do the following:

  1. On return, the cmd is created along with the subprocess which is saved into a variable
  2. The Popen stdout is put into a temporary file (in the cache dir) and is allowed to keep writing there as it goes
  3. The Popen is then started but we allow the after to end while doing two things: 1. while the subprocess is not completed we check the file every 50 ms or so and check if it spits out anything to be put into the console 2: we allow input during this time to be pushed to the subprocess 3. we set an after to run once the process is complete that will put in the directory and whatnot
  4. I might add that in this type the user can also cancel the subprocess with Control-c

This could theoretically prevent the app from crashing, open to new ideas though.

littlewhitecloud commented 1 year ago

Thats a great question. My current idea is this:

Right now, the way the terminal works is to run the command on <Return>. The running of this command takes place in an event which must complete before anything else can happen. To fix this, we could possibly do the following:

  1. On return, the cmd is created along with the subprocess which is saved into a variable
  2. The Popen stdout is put into a temporary file (in the cache dir) and is allowed to keep writing there as it goes
  3. The Popen is then started but we allow the after to end while doing two things: 1. while the subprocess is not completed we check the file every 50 ms or so and check if it spits out anything to be put into the console 2: we allow input during this time to be pushed to the subprocess 3. we set an after to run once the process is complete that will put in the directory and whatnot
  4. I might add that in this type the user can also cancel the subprocess with Control-c

This could theoretically prevent the app from crashing, open to new ideas though.

wow, great!