TkTerminal icon indicating copy to clipboard operation
TkTerminal copied to clipboard

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

Open Moosems opened this issue 2 years ago • 7 comments

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 avatar May 21 '23 19:05 Moosems

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.

Moosems avatar May 26 '23 13:05 Moosems

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

littlewhitecloud avatar May 26 '23 14:05 littlewhitecloud

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.

sumeshir26 avatar May 26 '23 14:05 sumeshir26

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

Moosems avatar May 26 '23 14:05 Moosems

So, is there any way to solve this problem?

littlewhitecloud avatar May 27 '23 01:05 littlewhitecloud

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.

Moosems avatar May 27 '23 12:05 Moosems

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!

littlewhitecloud avatar May 27 '23 13:05 littlewhitecloud