I am not at a computer right now, so cant tell you why your snippet doesn’t work. However, as you use Gmsh, you are able to mark the Facets for each boundary there. These can be loaded to dolfin with meshio. See Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio for a full code snippet of how to do it with 3D meshes. (Small modifications needed for 2D: i.e. Tetra->triangle, triangle->line, dimension in meshvaluecollection 2->1)