How to stop modal mode from unregister function? I'm writing below script which starts modal() function in register() function, however I could not stop modal() function when disable add-on.

is there any way to stop modal mode from unregister() function?

import bpy
from bpy.app.handlers import persistent


def get_invoke_context(area_type, region_type):
    for window in bpy.context.window_manager.windows:
        screen = window.screen
        for area in screen.areas:
            if area.type == area_type:
                break
        else:
            continue
        for region in area.regions:
            if region.type == region_type:
                break
        else:
            continue
        return {'window': window, 'screen': screen, 'area': area, 'region': region}


class ModalTest(bpy.types.Operator):

    bl_idname = "system.modal_test"
    bl_label = "Test"
    bl_description = "Test"

    def __init__(self):
        self.__timer = None

    def __handle_add(self, context):
        if self.__timer is None:
            self.__timer = context.window_manager.event_timer_add(
                0.1, context.window
            )
            context.window_manager.modal_handler_add(self)

    def __handle_remove(self, context):
        if self.__timer is not None:
            context.window_manager.event_timer_remove(self.__timer)
            self.__timer = None

    def modal(self, context, event):
        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        self.__handle_add(context)
        return {'RUNNING_MODAL'}


@persistent
def start_fn(scene):
    bpy.app.handlers.scene_update_pre.remove(start_fn)
    context = get_invoke_context('VIEW_3D', 'WINDOW')
    bpy.ops.system.modal_test(context, 'INVOKE_DEFAULT')


def register():
    bpy.utils.register_module(__name__)
    bpy.app.handlers.scene_update_pre.append(start_fn)


def unregister():
    bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
    register()
I would not recommend starting your modal operator in the register() function.  Typically you want to add a button or something to a UI panel, which the user can use to invoke your operator.

But if you're sure you want to start and stop your operator using register() and unregister(), then you could try something like this:

#insert this after your imports:
still_running = True

#insert this in your modal() method:
global still_running
if still_running == False:
    return {'FINISHED'}

#insert this in your unregister() method:
global still_running
still_running = False