Statement orders

jepler at unpythonic.net jepler at unpythonic.net
Sun Oct 2 15:06:20 EDT 2005


Here's one case where it's bad to call update.

	def perform_longrunning_calculation():
		time.sleep(1)
		app.update()
		time.sleep(1)

suppose you kick this off with a keybinding, such as:
	app.bind("c", lambda e: perform_longrunning_calculation())
the calculation takes 2 seconds, and after 1 second update() is called,
possibly to make sure that the user interface is repainted.

But imagine that in the first second, "c" has been pressed.  That event will
be handled, and perform_longrunning_calculation will be entered *again*,
recursively.  The nesting looks something like this:
  app's mainloop
    handling keypress
      perform_longrunning_calculation()
        app.update()
          handling keypress
            perform_longrunning_calculation()
by calling update_idletasks instead of update, the keypress event is not
handled, so it's impossible to enter perform_longrunning_calculation a
second time.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051002/615bc982/attachment.sig>


More information about the Python-list mailing list