python response slow when running external DLL

Peter Otten __peter__ at web.de
Fri Nov 27 04:18:35 EST 2015


jfong at ms4.hinet.net wrote:

> I am new to Python. As an exercise of it, I try to port a program which
> was written more than 10 years ago. This program use the Borland C++
> Builder as its GUI front end and a DLL does the real work(it will takes a
> few seconds to complete). I saw a strange phenomenon in the following
> codes. The "var_status.set('Download...')" statement seems was deferred
> and didn't show up until the external DLL job was finished and I can only
> saw the result of "var_status.set('Download OK')" statement which
> immediately follows. I try to do the DLL function in a thread(selected by
> using the "test" flag in codes), but it didn't help.
> 
> Can anyone tell me what's the point I was missed?

What does var_status.set() do? If it writes to stdout you may just need to 
flush().

Do you see the same behaviour when you replace mydll.SayHello() with 
something simple like time.sleep(1)?

> -------------------------
> 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
> --------------------------

As a general remark keep your test scripts as simple as possible. Example: 
If 

import mydll
print("Download...", end="")
mydll.SayHello()
print("OK")

showed the same behaviour it would be the ideal test script.




More information about the Python-list mailing list