Re: python response slow when running external DLL

2015-12-01 Thread jfong
Peter Otten at 2015/12/1 UTC+8 7:01:55PM wrote: > While the var_status.set() invoked from the second thread modifies some > internal data the main thread could kick in and modify (parts of) that same > data, thus bringing tkinter into an broken state. A simple example that > demonstrates the pr

Re: python response slow when running external DLL

2015-12-01 Thread Peter Otten
jf...@ms4.hinet.net wrote: > Peter Otten at 2015/11/28 UTC+8 6:14:09PM wrote: >> No, the point of both recipes is that tkinter operations are only ever >> invoked from the main thread. The main thread has polling code that >> repeatedly looks if there are results from the helper thread. As far I >

Re: python response slow when running external DLL

2015-11-30 Thread jfong
jf...@ms4.hinet.net at 2015/11/29 UTC+8 10:55:28AM wrote: > > > . > > > . > > > #do the rest > > > var_status.set('Download...') > > > _thread.start_new_thread(td_download, ()) #must use threading > > > > > > def td_download(): > > > result = mydll.SayHello() > >

Re: python response slow when running external DLL

2015-11-28 Thread jfong
Laura Creighton at 2015/11/28 UTC+8 6:52:25PM wrote: > I never saw the reply that Peter is replying to. > The threading module constructs a higher level interface on top of the > low level thread module. Thus it is the preferred way to go for > standard Python code -- and even Fredrik's recipe con

Re: python response slow when running external DLL

2015-11-28 Thread jfong
Peter Otten at 2015/11/28 UTC+8 6:14:09PM wrote: > No, the point of both recipes is that tkinter operations are only ever > invoked from the main thread. The main thread has polling code that > repeatedly looks if there are results from the helper thread. As far I > understand the polling method

Re: python response slow when running external DLL

2015-11-28 Thread Laura Creighton
In a message of Sat, 28 Nov 2015 11:13:38 +0100, Peter Otten writes: >jf...@ms4.hinet.net wrote: >> 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

Re: python response slow when running external DLL

2015-11-28 Thread Peter Otten
jf...@ms4.hinet.net wrote: > 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 tr

Re: python response slow when running external DLL

2015-11-27 Thread jfong
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 ther

Re: python response slow when running external DLL

2015-11-27 Thread Laura Creighton
In a message of Fri, 27 Nov 2015 13:20:03 +0100, Peter Otten writes: >A cleaner solution can indeed involve threads; you might adapt the approach >from (Python 2 code). But it is probably better to use threading http://code.activestate.com/recipes/82

Re: python response slow when running external DLL

2015-11-27 Thread Peter Otten
jf...@ms4.hinet.net wrote: > Peter Otten at 2015/11/27 UTC+8 5:19:17 PM wrote: > > Hi! Peter, thanks for your prompt reply. > >> What does var_status.set() do? If it writes to stdout you may just need >> to flush(). > >var_status is a StringVar which binds to a lable's textvariable. I use

Re: python response slow when running external DLL

2015-11-27 Thread jfong
Peter Otten at 2015/11/27 UTC+8 5:19:17 PM wrote: Hi! Peter, thanks for your prompt reply. > What does var_status.set() do? If it writes to stdout you may just need to > flush(). var_status is a StringVar which binds to a lable's textvariable. I use this label as the status bar to show mes

Re: python response slow when running external DLL

2015-11-27 Thread Peter Otten
jf...@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 phenom

python response slow when running external DLL

2015-11-26 Thread jfong
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