Page 1 of 1

Debugging external python script with pdb.

PostPosted: Sat Jan 20, 2024 7:55 am
by anitchalk
Hi, I'm working on an external python script that I call from a schedule (i.e. under actions where you select "Execute Script (Script and File Actions)" ). I "feel" like I was able to do this before the last time I sat down and dove into something new. But maybe I'm fooling myself. I know this works during plugin development, so maybe that's what I'm thinking of and conflating the two. I'm running the following from the cmd line:
Code: Select all
 /usr/local/bin/indigo-host -d 100 -x ./foo.py

100 appears to be for pdb when I run indigo-host --help:
Code: Select all
  -d {0,100,101,102,200}, --debug {0,100,101,102,200}
                        Debug mode: PDB: 100, PuDB: 101, PyCharm: 102, Debug shell: 200

I've added calls to indigo.debugger() in my script, but as far as I can tell, execution just halts there. I've verified this by adding logging before and after the call to indigo.debugger(). As if some window is opening somewhere where I can step into the debugger but I don't see it.
So when I hit ctrl-c in the terminal window where I'm running indigo-host, after it exits, I see the following in the indigo logs:
Code: Select all
   Error                           ElementNotFoundError -- could not find plugin com.perceptiveautomation.indigoplugin.scriptexecutor.external

So I guess first question is.... am I being dumb in thinking this should work at all?
And if this should be working, any ideas why it isn't and also is the above ElementNotFoundError related?

Re: Debugging external python script with pdb.

PostPosted: Mon Jan 22, 2024 2:49 pm
by jay (support)
Unfortunately, I don't think debugging scripts will work because the the special environment we have to set it up in.

One thought, since you seem to be familiar with plugins, would be to put the logic of your script into a plugin just for testing purposes. Then you can use the debugger to debug the plugin.

Re: Debugging external python script with pdb.

PostPosted: Wed Jan 24, 2024 11:12 am
by anitchalk
ooh, genius idea. Didn't even occur to me. May as well set up a 'blank' plugin for all future testing of scripts!

Thanks

Re: Debugging external python script with pdb.

PostPosted: Thu Feb 29, 2024 11:06 am
by anitchalk
I understand that it is recommended to place all external scripts in /Library/Application Support/Perceptive Automation/Scripts (as indicated here). But, I like to keep test and production in separate directories so I can quickly switch back to a working copy if I'm not finished with updates.

When I click on the "Choose..." script button in the Actions dialog (when Type = "Execute Script"), the file dialog box that comes up always defaults to the indigo Scripts directory vs where the current file is located. I might be missing something elsewhere, but it seems that if my script location isn't in the recommended Scripts directory I don't know which one I'm currently pointing to at first glance? Obviously I can go and pick the one I want, but would be nice to see what I'm looking at without having to re-pick every time to be sure.

Totally understand that if no file has been set before in the dialog, it should always default to /Library/Application Support/Perceptive Automation/Scripts ! But when it has been set would be nice to know what is actually running.

Re: Debugging external python script with pdb.

PostPosted: Thu Feb 29, 2024 12:21 pm
by anitchalk
Also.. obviously goes without saying this isn't very important. I will likely make my environment better by symlinking from the default location to whatever version I want to run/test. But still seems useful for others that might be confused on what is or isn't running.

Re: Debugging external python script with pdb.

PostPosted: Thu Feb 29, 2024 1:28 pm
by matt (support)
We'll look into this. I would expect it to open to the folder containing the existing script as well.

Re: Debugging external python script with pdb.

PostPosted: Thu Feb 29, 2024 2:14 pm
by anitchalk
If it matters, I'm on 2023.2.0 (client and server)