[Tutorial - Python - Debugging Ableton Remote Scripts] How To

Share your favorite Ableton Live tips, tricks, and techniques.
Post Reply
ginwakeup
Posts: 4
Joined: Sun Sep 20, 2020 5:19 pm

[Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by ginwakeup » Sun Oct 04, 2020 2:33 pm

Hello!

I've been writing few remote scripts for Ableton, and something I've struggled quite a bit was debugging them.

It's a personal thing, usually when I code, especially in an environment that I don't know, I need to debug it to understand what's behind the curtain.
Anyway, how?

I've used remote pdb, here's what you have to do in order to use it [Windows]:
  • Pip install remote_pdb in Ableton Remote Scripts folder
create any virtual environment with python 2.7, or use your system interpreter and run the following command:

Code: Select all

pip install remote-pdb --target="C:\ProgramData\Ableton\Live 10 Standard\Resources\MIDI Remote Scripts\"
The target folder is your Midi Remote Scripts folder.
This will install remote_pdb and make it accessible in your remote scripts.
  • Enable telnet in Windows.
Open your control panel, click Programs, click Turn WIndows Features On/Off.
Look for Telnet, enable it. This will allow you to connect to the pdb process in Ableton.
  • The following point is my own pattern, you can do this differently. I created a singleton class which runs the connection listener. This has to be done ONCE, or the process will get stuck and you'll have to use a different terminal each time you run the connection listener creation. The singleton pattern creates the listener just once time in a Debugger singleton class, that you can later on access quickly.

Code: Select all

from .remote_pdb import RemotePdb

class Singleton(type):
    _instances = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]


class Debugger:
    __metaclass__ = Singleton
    def __init__(self):
        self._remote_pdb = RemotePdb('127.0.0.1', 4444) # 444 is my port, you can use another one if you prefer.

    def set_trace(self):
        self._remote_pdb.set_trace()
  • Set your breakpoints.
In your code, set your breakpoints in the following way:

Code: Select all

Debugger().set_trace()
Remember, Debugger is the singleton class we created in the previous point, so you'll have to import it from wherever you created it.

  • Run Ableton, and open a terminal window.
Once Ableton loads, if you select your remote midi script, as soon as it hits the breakpoint the Ableton process should freeze.
This is normal, as the process is awaiting on the python debugger connection.
In your terminal, run the following command:

Code: Select all

telnet 127.0.0.1 4444

Check pdb page for the commands, few of them quickly:
  • n: Next line of code
  • s: Step inside code
  • c: continue to next breakpoint.
  • w: shows a traceback around the current line of code.
Hopefully this helped someone.

Iacopo

slemerdy
Posts: 3
Joined: Fri Feb 23, 2018 5:19 pm

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by slemerdy » Tue Feb 09, 2021 10:49 am

Hello,
Seems to be interesting indeed ! Thanks for the info.
I need to install Serial to control a UART based device with my remote script. Do you think I could use the command you gave. I will try that !

The Rabbits
Posts: 126
Joined: Tue Apr 07, 2020 2:23 pm

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by The Rabbits » Wed Feb 10, 2021 12:14 am

Thanks for the information. I've been trying to figure out how to debug my scripts. Currently doing it old-school with logging and the
-AutoShowPythonShellOnError flag in options.txt.

The Rabbits
Posts: 126
Joined: Tue Apr 07, 2020 2:23 pm

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by The Rabbits » Fri Feb 12, 2021 5:52 am

Quick question, is there a way to get ableton to reload/recompile a script without restarting it? That's the most time consuming part of the process.

Thanks

ginwakeup
Posts: 4
Joined: Sun Sep 20, 2020 5:19 pm

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by ginwakeup » Sat Apr 03, 2021 9:53 pm

The Rabbits wrote:
Fri Feb 12, 2021 5:52 am
Quick question, is there a way to get ableton to reload/recompile a script without restarting it? That's the most time consuming part of the process.

Thanks
Hey,

you can try using python "reload" builtin or sometimes changing the control surface from options - preferences - MIDI works fine.

lu57
Posts: 22
Joined: Mon Jan 20, 2020 9:02 am
Contact:

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by lu57 » Wed May 26, 2021 1:25 pm

Hi!
Many thanks for the tip! Do you know why breakpoints do not work after a 'continue'?
For example the set_trace is triggered, I connect via telnet, fiddle a bit, and then add another breakpoint and type 'c'. The breakpoint is never triggered...

leonardmreidy
Posts: 2
Joined: Mon Dec 27, 2021 3:33 pm

Re: [Tutorial - Python - Debugging Ableton Remote Scripts] How To

Post by leonardmreidy » Mon Dec 27, 2021 3:41 pm

Hi There!

I was wondering if you can help. I followed the instructions in this post and I have not had much success. The Log.txt file indicates that remote_pdb connection is opened, but Ableton never pauses when it reaches the breakpoint as such and the logs indicate that an error is thrown. I have tried many different things and the result is always the same. I have never succeeded in opening the telnet connection from the command prompt either. I have enabled the Telnet Client in Windows, and I have tried disabling the firewall completely, partially, with and without adding inbound rules, and so on. Pretty much all the standard recommendations I can find online, and any sensible variation I can think of. No luck. I would really appreciate it if you had any suggestions. Below, there is an excerpt of the errors I noted in the logs:

Code: Select all

2021-12-27T15:21:54.586878: info: RemoteScriptError:   File "C:\ProgramData\Ableton\Live 11 Suite\Resources\MIDI Remote Scripts\remote_pdb.py", line 76, in __init__

2021-12-27T15:21:54.587508: info: RemoteScriptError:     
2021-12-27T15:21:54.587731: info: RemoteScriptError: cry("RemotePdb session open at %s:%s, waiting for connection ..." % listen_socket.getsockname())
2021-12-27T15:21:54.587889: info: RemoteScriptError: 

2021-12-27T15:21:54.588062: info: RemoteScriptError:   File "C:\ProgramData\Ableton\Live 11 Suite\Resources\MIDI Remote Scripts\remote_pdb.py", line 20, in cry

2021-12-27T15:21:54.589076: info: RemoteScriptError:     
2021-12-27T15:21:54.589241: info: RemoteScriptError: stderr.flush()
2021-12-27T15:21:54.589438: info: RemoteScriptError: 

2021-12-27T15:21:54.589676: info: RemoteScriptError: AttributeError
2021-12-27T15:21:54.589859: info: RemoteScriptError: : 
2021-12-27T15:21:54.590033: info: RemoteScriptError: 'NoneType' object has no attribute 'flush'
2021-12-27T15:21:54.590197: info: RemoteScriptError: 

2021-12-27T15:21:54.590275: info: Exception: Script could not be loaded.
2021-12-27T15:21:54.594480: info: Python: CRITICAL:remote_pdb:593 - RemotePdb session open at 127.0.0.1:4444, waiting for connection ...
2021-12-27T15:21:54.603802: info: RemoteScriptError: Traceback (most recent call last):

2021-12-27T15:21:54.604103: info: RemoteScriptError:   File "C:\Users\leona\Documents\Ableton\User Library\Remote Scripts\BlockLive11\__init__.py", line 28, in create_instance

2021-12-27T15:21:54.604863: info: RemoteScriptError:     
2021-12-27T15:21:54.605043: info: RemoteScriptError: return BlockLive11(c_instance)
2021-12-27T15:21:54.605189: info: RemoteScriptError: 

2021-12-27T15:21:54.605333: info: RemoteScriptError:   File "C:\Users\leona\Documents\Ableton\User Library\Remote Scripts\BlockLive11\BlockLive11.py", line 83, in __init__

2021-12-27T15:21:54.606150: info: RemoteScriptError:     
2021-12-27T15:21:54.606323: info: RemoteScriptError: Debugger().set_trace()
2021-12-27T15:21:54.606466: info: RemoteScriptError: 

2021-12-27T15:21:54.606625: info: RemoteScriptError:   File "C:\Users\leona\Documents\Ableton\User Library\Remote Scripts\BlockLive11\BlockLive11.py", line 67, in __init__

2021-12-27T15:21:54.607595: info: RemoteScriptError:     
2021-12-27T15:21:54.607811: info: RemoteScriptError: self._remote_pdb = RemotePdb('127.0.0.1', 4444) # 444 is my port, you can use another one if you prefer.
2021-12-27T15:21:54.607974: info: RemoteScriptError: 

2021-12-27T15:21:54.608131: info: RemoteScriptError:   File "C:\ProgramData\Ableton\Live 11 Suite\Resources\MIDI Remote Scripts\remote_pdb.py", line 76, in __init__

2021-12-27T15:21:54.608959: info: RemoteScriptError:     
2021-12-27T15:21:54.609166: info: RemoteScriptError: cry("RemotePdb session open at %s:%s, waiting for connection ..." % listen_socket.getsockname())
2021-12-27T15:21:54.609325: info: RemoteScriptError: 

2021-12-27T15:21:54.609503: info: RemoteScriptError:   File "C:\ProgramData\Ableton\Live 11 Suite\Resources\MIDI Remote Scripts\remote_pdb.py", line 20, in cry

2021-12-27T15:21:54.610192: info: RemoteScriptError:     
2021-12-27T15:21:54.610364: info: RemoteScriptError: stderr.flush()
2021-12-27T15:21:54.610499: info: RemoteScriptError: 

2021-12-27T15:21:54.610672: info: RemoteScriptError: AttributeError
2021-12-27T15:21:54.610814: info: RemoteScriptError: : 
2021-12-27T15:21:54.610951: info: RemoteScriptError: 'NoneType' object has no attribute 'flush'
2021-12-27T15:21:54.611137: info: RemoteScriptError: 

2021-12-27T15:21:54.611210: info: Exception: Script could not be loaded.
All advice welcome!

Kind regards,
Leonard

Post Reply