I want to automate a periodic refresh of the QGIS map canvas with updated shapefiles. A Python plugin or console script does not allow the map to update until the script terminates. Is there a way to force a map refresh in a running plugin or script, or is a stand-alone app required?

Using v1.7.4 now but could migrate to newer version.

1 Answer 1


You can use the python threading library to run a function periodically:

I have used the following statements to remove a set of graphics after 3 seconds:

from threading import Timer
Timer( 3, self._clearGraphicLayer, ()).start()

def _clearGraphicLayer(self):
  for graphic in  self.graphicsLayer: 

  self.graphicsLayer = []

And if needed you can have the callback function restart the timer if a certain condition is not met. But look out if you use this module wrong you can crash the entire application.

More info: https://docs.python.org/2/library/threading.html

  • You may want to consider to update to QGIS 2.4 which has improved considerably concerning thread-safety when iterating layer data. Aug 20, 2014 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.