Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99655

Re: python response slow when running external DLL

Newsgroups comp.lang.python
Date 2015-11-27 23:37 -0800
References <dc290806-c537-4546-b802-88dff14d81c0@googlegroups.com> <mailman.169.1448615930.20593.python-list@python.org> <f4cf8b4f-94e7-4d97-b144-65f59c20fbc1@googlegroups.com> <mailman.173.1448626828.20593.python-list@python.org>
Message-ID <d6c59a36-38ba-4f26-b949-18f2b226e7e3@googlegroups.com> (permalink)
Subject Re: python response slow when running external DLL
From jfong@ms4.hinet.net

Show all headers | View raw


Peter Otten at 2015/11/27 UTC+8 8:20:54PM wrote:

> Quick-fix example:
> def download():
>     var.set("Starting download...")
>     root.update_idletasks()
>     time.sleep(3)
>     var.set("... done")

Thanks, Peter, The update_idletasks() works. In my trivial program it's easy to apply for there are only two places call the DLL function.

> A cleaner solution can indeed involve threads; you might adapt the approach 
> from <http://effbot.org/zone/tkinter-threads.htm> (Python 2 code).

Using thread is obviously more logical. I think my mistake was the "while busy:  pass" loop which makes no sense because it blocks the main thread, just as the time.sleep() does. That's why in your link (and Laura's too) the widget.after() scheduling was used for this purpose.

From what I had learned here, the other way I can do is making the codes modified as follows. It will get ride of the "result" and "busy" global variables, but it also makes the codes looks a little ugly. I think I will take the update_idletasks() way in this porting for it seems more simpler, and can be used on thread or non-thread calling. Thank you again.
    .....
    .....
    #do the rest
    var_status.set('Download...')
    _thread.start_new_thread(td_download, ())  #must use threading

def td_download():
    result = mydll.SayHello()
    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')

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-26 23:51 -0800
  Re: python response slow when running external DLL Peter Otten <__peter__@web.de> - 2015-11-27 10:18 +0100
    Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-27 03:14 -0800
      Re: python response slow when running external DLL Peter Otten <__peter__@web.de> - 2015-11-27 13:20 +0100
        Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-27 23:37 -0800
          Re: python response slow when running external DLL Peter Otten <__peter__@web.de> - 2015-11-28 11:13 +0100
            Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-28 18:55 -0800
              Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-30 17:03 -0800
              Re: python response slow when running external DLL Peter Otten <__peter__@web.de> - 2015-12-01 12:01 +0100
                Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-12-01 19:58 -0800
          Re: python response slow when running external DLL Laura Creighton <lac@openend.se> - 2015-11-28 11:51 +0100
            Re: python response slow when running external DLL jfong@ms4.hinet.net - 2015-11-28 19:04 -0800
      Re: python response slow when running external DLL Laura Creighton <lac@openend.se> - 2015-11-27 13:49 +0100

csiph-web