Problem with timing, again:

Peter Hansen peter at engcorp.com
Sun Jul 29 01:30:27 EDT 2001


Jeremy Moles wrote:
> 
> It works, but it won't respond, and it won't let the
> button go. What am I doing wrong?

Classic mistake.

> ____________________________________________
> 
>     def dostuff(self):
[...]
>       def domorestuff():
>          z=ftplib.FTP(host='ahost')
>          z.login(user='asuer',passwd='apassword')
>          z.cwd('public_html')
>          z.storlines('STOR IP.html',open('D:\\Python\\IP.html','r'))
>          z.close()
>       while 1:
>          domorestuff()
>          time.sleep(15)
> 
> _______________________________________________
> 
> Anyways, the program works - but the gui itself freezes up - it's as if the
> button is stuck. You guys were so helpful last time, any advice this time?

It is typical in GUI programs to have to release the CPU quickly 
in order to keep responsiveness in the user interface.  There is
generally a way of having a function called periodically to do
some work (e.g. your domorestuff()) but you have to use some
feature of the GUI toolkit to set this up, not implement it 
yourself with time.sleep() as you have done.

Sorry, I'm not Tk expert so I can't point you to the specific
answer -- only generalities here. :)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list