Debugging mycroft

When making skills or extend the core it is great to have a way to debug while running. Debugging in the THEIA IDE has been one of my wishes, and I have been working on that for some time. I have been trying and trying lots of things and I have experiansed many errors. But now I got something working.

The latest build of Theia-for-Mycroft (only picroft version for now) do have python debugging working and ready to debug mycroft skills and Mycroft core.

To test and/or use install TheiaIDE skill from Mycroft market. If allreddy using the skill remove it and install it again as it then will pull down latest theia-for-mycroft build. Mycroft Marketplace

How to setup debuging:

First you need to add ptvsd by

mycroft-pip install ptvsd

Then you need to add some lines to /home/pi/mycroft-core/mycroft/skills/main.py

at the top of the file at line 36 add

import ptvsd

at line 46 add

# start remote debug if set true in config
config = Configuration.get()
if config.get('remote-debug', False):
    ptvsd.enable_attach()

Sadly that isnt enough, as the stop-mycroft.sh does not stop corretly if debuging is active and that makes lots of haning processes running and breaks debugging. So some change to that is needed as well

You need to change /home/pi/mycroft-core/mycroft/skills/stop-mycroft.sh

line 56 change to

pkill -SIGINT -f "python3 -m mycroft.*${1}"

line 73 change to

pkill -SIGKILL -f "python3 -m mycroft.*${1}"

Now we are reddy to rock…well to activate debugging add this to mycroft.conf

"remote-debug": true

Restart mycroft and debug is now posible

How to use debug in THEIA IDE:

In THEIA IDE you can now open a skill .py file, and set one or more breakpoints, start the debugger and select Python: Mycroft and start debugging. You can see it is getting the mainthread and all the subthreads

When it hits your breakpoint it will stop and wait. Now you can se where, and what variables and lots of other debug stuff.

Remote debugging from VS-code:

As far as I understands - the changes to mycroft-core should make it posible to use remote debuging (attach) from VS-code and other IDE’s to, so the debugging isnt just for THEIA IDE.
Install Python extension from Mycroft Python - Visual Studio Marketplace wich are same plugin as used in THEIA IDE
But I hassnt tryed remote debuging from vscode yet.

Add debug to mycroft-core

Later - if this seems to work well I will make a PR so this stuff can get into mycroft-core making debuging easy for everyone out of the box when using mycroft.

Some issues:

Sometimes when something goes bad there will be some parentless mycroft.skills processes running and that breaks lots of stuff. To get back up restart skills or all as that will kill the parentles processes.

As I see a normal run of mycroft has only one mycroft.skills process, but when debug is set to true there is four extra.

Feedback, discussion and more:

Please give feedback and help getting this even better. Here or on mycroft-chat or on github issue Issues · andlo/theia-ide-skill · GitHub

Happy mycrofting and debuging
/Andreas

4 Likes