运行外部DLL时python响应缓慢

时间:2015-11-24 02:30:59

标签: python dll

我是Python新手。作为一种练习,我尝试移植一个十多年前编写的程序。该程序使用Borland C ++ Builder作为其GUI前端,DLL完成实际工作(完成需要几秒钟)。我在下面的代码中看到了一个奇怪的现象。 “var_status.set('Download ...')”语句似乎是延迟的,直到外部DLL作业完成才显示,所以我只能看到结果 “var_status.set('下载OK')”声明。我尝试在一个线程中执行DLL函数(通过在代码中使用“test”标志选择),但它没有帮助。

谁能告诉我,我错过了什么?

else:  # has to run program as the administrator
def download():
    global iniFilename
    if test:  global result, busy
    ini = iniFilename
    iniFilename = "c:\\$$temp.in3"
    saveIniFile()
    iniFilename = ini
    #do the rest
    var_status.set('Download...')
    if not test:
        result = mydll.SayHello()
    else:
        busy = True
        _thread.start_new_thread(td_download, ())
        while busy:  pass
    if result:
        var_status.set("Download Fail at %s" % hex(result))
        showerror('Romter', 'Download Fail')
    else:
        var_status.set('Download OK')            
        showinfo('Romter', 'Download OK')

if test:
result = 0x5555
busy = True
def td_download():
    global busy, result
    result = mydll.SayHello()
    busy = False

1 个答案:

答案 0 :(得分:0)

问题解决了。在“var_status.set(”正在下载...“)之后立即执行”root.update_idletasks()“

相关问题