Custom End a Modal operator Blender Python
<p>I have the following code:</p>

<pre><code>class audio_visualizer_create(bpy.types.Operator):
    bl_idname = "myop.audio_visualizer_create"
    bl_label = "Audio Visualizer Create"
    bl_description = ""
    bl_options = {"REGISTER"}


    @classmethod
    def poll(cls, context):
        return True

    def invoke(self, context, event):
        context.window_manager.modal_handler_add(self)
        scene = bpy.context.scene




        ##VARIABLES
        type = scene.audio_visualizer_type
        subtype = scene.audio_visualizer_subtype
        axis = scene.audio_visualizer_axis
        object = scene.audio_visualizer_other_sample_object
        scalex = scene.audio_visualizer_sample_object_scale[0]
        scaley = scene.audio_visualizer_sample_object_scale[1]
        scalez = scene.audio_visualizer_sample_object_scale[2]
        object = scene.audio_visualizer_other_sample_object
        bars = scene.audio_visualizer_bars_number

        print(bars)
        print(scaley)
        print(scene.audio_visualizer_bars_distance_weight)

        ##GETTING THE OBJECT
        if object == "OTHER":
            object = scene.audio_visualizer_other_sample_object

        ##Setting Up the bars
        total_lenght = (scaley*bars) + (scene.audio_visualizer_bars_distance_weight/100*(bars-1))

        for i in range(0, bars):
            bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=bpy.context.scene.layers)
            bpy.context.object.scale = (scalex,scaley,scalez)
            bpy.context.object.location.y = total_lenght/bars*i


        is_finished = True
</code></pre>

<blockquote>
  <p>At this Point i want to finish the Modal Operator.</p>
</blockquote>

<pre><code>        return {"RUNNING_MODAL"}

    def modal(self, context, event):


        if event.type in {"ESC"}:
            print("You've Cancelled The Operation.")

            return {"CANCELLED"}

        if event.type in {"MIDDLEMOUSE", "RIGHTMOUSE", "LEFTMOUSE"}:
            return {"FINISHED"}

        return {"FINISHED"}
</code></pre>

<p>But If I put return {"FINISHED"} instead of return {"RUNNING_MODAL"} blender Crashes or freezes, is there any way to end the operator?</p>