42. gui.drawlock — A locking mechanism for the drawing functions.

42.1. Classes defined in module gui.drawlock

class gui.drawlock.DrawLock[source]

A timed lock to slow down drawing processes


Wait for the drawing lock to be released.

This method can be called to wait until the lock is released, while still processing GUI events.


Lock the drawing function for the next time seconds.

If a no time is specified, a global value is used.


Lock the drawing function indefinitely.


Release the lock on the drawing function.

If a timer is running, cancel it.


Release the lock and prevent waits until allow() is called.


Allow draw waits.

This is called after a free() to reinstall the draw locking.

class gui.drawlock.Repeater(func, duration=-1, maxcount=-1, sleep=0)[source]

Repeatedly execute a function.

The Repeater class provides functionality to repeatedly execute a function, while allowing the GUI to process events so that user interactivity can continue. It also avoids using too much CPU time while running empty. The function can be repeated until one of the following conditions is met:

  • the called function returns a value that evaluates to True
  • a specified time has elapsed
  • a number of executions has been reached
  • and external event stops the execution


  • func: if callable, this function will be called repeatedly why the Repeater class is active. The function will be passed all the extra parameters *args and **kargs. If the function returns a value that does not evaluate to False, execution is halted.
  • duration: max duration for the repeated execution. If < 0, repeats indefinitely.
  • maxcount: max number of executions. If < 0, there is no limit.
  • sleep: extra time to sleep between two executions. The actual time between two executions may be higher, because any GUI events will also be executed. If your function does not do anything, setting a value > 0 is recommended to avoid high CPU usage while running idle.

Execution is started by calling the start() method. The method returns after some event has made it to stop, with an exitcode of:

  • 1, if the stop() method was used
  • 2, if a timeout occurred
  • 3, if the maximum number of excutions occurred,
  • or else, with the value returned by the function.
start(*args, **kargs)[source]

Start repeated execution


Stop the repeater because of a timeout


Interrupt a repeater with given exitcode