I suggest you start by doing the initialization once before the loop using Gmsh; Gmsh.initializie(), and for each loop iteration you use gmsh.clear() and/or gmsh.open() (see their docstrings). Finally, outside of the loop you can call Gmsh.finalize().