<p>我需要知道你是否在使用文本框显示大量数据时遇到过减速甚至挂起的情况。你知道吗</p>
<p>在我的例子中,我使用subprocess运行一个模拟脚本,它的stdout显示在文本框中。
文本可以是MBs。你知道吗</p>
<p>我尝试了两种实现:</p>
<p>1)文本框等待模拟(子进程)完成,然后才能显示标准输出数据。结果很好。
但唯一的问题是我想实时显示stdout数据。你知道吗</p>
<p>2)我开始在这里实时显示数据文本框很容易显示小进程的标准数据。
但是,当我运行长时间的模拟脚本时,它们被夹在中间。
我知道由于没有生成相关的输出文件,模拟脚本的执行被暂停。
屏幕悬挂与我们在windows中遇到的类似。你知道吗</p>
<p>关于模拟脚本:这是一个脚本,可以使用其他脚本运行许多其他子进程(一次一个子进程)。你知道吗</p>
<p>如果你有什么解决办法,请指教?我可以用画布代替文本框吗?有帮助吗?你知道吗</p>
<p>运行函数如下:</p>
<pre><code>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()
</code></pre>
<p>主要目标是运行子进程并在textbox上显示所有输出,从而将用户与命令提示符界面断开链接。
<strong><em>我调试尝试的备注:</em></strong>
当我用一个打印数字1到5000的示例脚本(sample\u script)运行同一个gui脚本时,它运行得很好。这意味着脚本的流程是正常的。
但测试环境和我的实际脚本运行环境之间有一个主要区别:那就是我的子进程运行脚本(说:-脚本1)实际上是一个运行其他脚本的父csh脚本(说:-脚本1.1在它下面写1.2)。
因此,请注意以下几点:</p>
<blockquote>
<p>The execution halts when script1 has issued commands to launch script1.1
The sample_script(which prints number) is working fine though.</p>
</blockquote>
<p><strong>调试更新:</strong>
我将以下脚本作为示例脚本运行,并注意到以下结果:</p>
<pre><code>set i = 450
while ($i > 1)
echo i is $i
set i = `expr "$i" - 1`
end
</code></pre>
<blockquote>
<p>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.
<strong>When i am running i = 550, using print statements i found that the execution of sample_script stops at i = 98.</strong>
I am unable to figure out why!!</p>
</blockquote>
<p><strong>如果您需要更多信息,请及时通知我。</strong></p>