Immediately cancel running modal operators from outside instance?

What is the proper way to immediately cancel a running modal operator from outside its instance?

It needs to cancel itself, but you may use a global property which can be controlled from outside, or have an internal variable so you know that it is already running and return {‘FINISHED’} in both, invoke() and modal() if the operator is called a second time.

Yeah, that’s my problem… I would like to close it externally, but setting a “quit” flag is useless, since the flag is only checked on receiving an event. The code requiring that operator be all canceled and cleaned up would be finished before the operator even checks the flag.

Is there any API function (no matter how hacky) that would cause an event for the operator and block until the event was processed?

Ctrl+C in the system console on windows kills a modal operator (actually raises KeyboardInterrupt exception), I don’t know of any other way

I also noticed that there seems to be no way to handle reloads. Pressing F8 while the operator is still running results in an error and there appears to be no way to handle it. No method to cancel a modal operator on reload requests. It would appear the only way to gracefully handle a reload would be to override F8 with a custom op that disables the addon, reloads, and then enables the addon.

Another question: Is there a way to keep track of modal operators called from python? If I call bpy.ops.transform.translate(‘INVOKE_DEFAULT’), is there a way to check if it finished or is still running?

not for python as far as I know