Correct way to disable a service addon

What is the correct way to disable a service addon, the example code from the wiki:-

Code:
import time
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not monitor.abortRequested():
        # Sleep/wait for abort for 10 seconds
        if monitor.waitForAbort(10):
            # Abort was requested while waiting. We should exit
            break
        xbmc.log("hello addon! %s" % time.time(), level=xbmc.LOGDEBUG)

Crashes Kodi 17.3 Linux when pressing the Disable button Sad But works fine under 17.3 windows.

I get no crash log and these are the last entrys in the kodi.log file:-

Code:
19:50:05.986 T:3619525536    INFO: CPythonInvoker(15, /storage/.kodi/addons/service.test/main.py): script successfully run
19:50:05.986 T:3619525536    INFO: CPythonInvoker(15, /storage/.kodi/addons/service.test/main.py): waiting on thread 18446744072996598688
19:50:06.787 T:4118914672   DEBUG: CPythonInvoker(15, /storage/.kodi/addons/service.test/main.py): script termination took 803ms
19:50:32.397 T:3679450016   DEBUG: Thread JobWorker 3679450016 terminating (autodelete)
19:50:32.398 T:3844314016   DEBUG: Thread JobWorker 3844314016 terminating (autodelete)
19:50:32.398 T:3909088160   DEBUG: Thread JobWorker 3909088160 terminating (autodelete)
19:50:32.526 T:4031767456   DEBUG: Thread JobWorker 4031767456 terminating (autodelete)

Then the UI just hangs.

Any help please.