Process meshes that have multiple users only once in script
You could use an array to check if a mesh has been already modified.

theScene = bpy.context.scene

# Store selected objects
theSelected = bpy.context.selected_objects
theObjects = set([obj for obj in theSelected if obj.type == 'MESH'])

#all the meshes here:
meshes = []


# Iterate over selected objects
for obj in theObjects:
    # Set this object as active
    theScene.objects.active = obj
    mesh = obj.data

    # Do something if the mesh isn't in the array yet
    if (not mesh in meshes):
        meshes.append(mesh)

        # Select all edges in edit mode
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.mesh.select_mode(type='EDGE')
        bpy.ops.mesh.select_all(action = 'SELECT')

        print(meshes)

        # Subdivide
        bpy.ops.mesh.subdivide()

        # Toggle Object Mode to select next object
        bpy.ops.object.mode_set(mode='OBJECT')