I need to know if you ever faced slowing or even hang while using text box to display large amount of data.
In my case I am running a simulation script using subprocess and its stdout is displayed in text box.
The text can be in MBs.
I tried two implementations:
1) The textbox waited for the simulation(subprocess) to finish before it can display the stdout data. This worked out pretty fine.
But the only issue was that i wanted to display the stdout data in real time.
2) I started displaying the data real time-Here the text box was easily displaying stdout data for small processes.
However, when i run long simulation scripts, they are stuck in between.
I know execution of simulation script is halted as relevant output files were not generated.
The screen hang is similar to one we experience in windows.
About Simulation script: This is a single script which can run many other child process (one at a time) using other scripts.
Please advice if you have any solution? Can i use canvas instead of text box? will it help?
Please find the run function as below:
def run():
filename = str(run_file_name.get())
command.set("Running "+filename)
#Creating new Window to display output
t = Toplevel(root)
t.title('output Run Display')
t.geometry('800x1000-5+40')
t.state('normal')
little = Label(t, text="OUTPUT LOG").grid(column = 0, row = 0)
log = Text(t, state='disabled', width=115, height=150, wrap='none')
log.grid(row = 1, column = 0)
test=subprocess.Popen(filename,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)# stderr=subprocess.PIPE)
#stdout
while True:
line_out = test.stdout.readline()
line_er = test.stderr.readline()
if line_out == "" and line_er == "":
break
else:
log['state'] = 'normal'
log.insert('end', line_out)
log.insert('end', line_er)
log['state'] = 'disabled'
print line_out
print line_er
t.update()
The main target is to run the subprocess and show all the output on textbox, hence to delink the user from command prompt interface.
Remark from my debug Attempt:
When I ran the same gui script with a sample script(sample_script) which prints number 1 to 5000, it was running fine. That means the flow of the script is ok.
But there is one major difference between test environment and my actual script run environment: that is my subprocess run script(say:- script_1) is actually a parent csh script which runs other scripts(say:- script1.1 and script 1.2) under it.
Hence Please note following points:
The execution halts when script1 has issued commands to launch script1.1
The sample_script(which prints number) is working fine though.
Debug Update:
I ran the following script as sample_script and noticed the following results:
set i = 450
while ($i > 1)
echo i is $i
set i = `expr "$i" - 1`
end
By running the above example, i found that the output appears only after subprocess is complete.
However, In my case if i put i = 550, the terminal stays in wait state and output doesn’t appear(even after many minutes). Hence the process stuck.
The i = 550 number may be higher or lower for you.
When i am running i = 550, using print statements i found that the execution of sample_script stops at i = 98.
I am unable to figure out why!!
PLEASE do prompt me if you need anymore information.
I’ve used tk for close to 20 years and haven’t noticed any problems with large amounts of text, though I don’t guess I’ve ever tried to load up more than a few 10’s of thousands of lines. Just how much data are you trying to show? Are you using a large number of tags and different fonts, or is this just plain text?
Certainly, the whole GUI will become unresponsive if you’re spawning a subprocess and waiting for it to complete. Tk is single threaded, so while you’re waiting for a process to finish there’s no way for the event loop to run and thus your program will freeze. You need to make sure that whatever scheme you use to run the process and manage it’s output doesn’t block the event loop.
My guess is, this isn’t a limitation of the text widget and switching to the canvas won’t help. The problem is probably in your code, but without seeing your code it’s impossible to come up with a solution.