Startup script on OSX [python]

Supporting 10.7 and up
cupofnestor
Fresh meat
Posts: 4
Joined: Tue Jul 15, 2014 1:24 pm
Contact:

Startup script on OSX [python]

Postby cupofnestor » Tue Jul 15, 2014 1:35 pm

I've got three interfacekit 8/8/8's attached to a macMini. I've written a python script to play sounds based on analog input using pygame. The script runs great when initialized from the shell, however need it to run when the machine boots.

I've tried all of my tricks (I do this kind of thing quite a bit :oops: ) but I can't seem to get ahold of the interface kits when I run the script as a (user or root) LaunchAgent (directly with python, or via bash script), via applescript, etc...

pastebin of my script

I'm on site, so time is short. :? Short of running the script with ssh every time, I'm out of ideas.
Anybody have experience that might help me out?

User avatar
Patrick
Lead Developer
Posts: 3067
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Startup script on OSX [python]

Postby Patrick » Tue Jul 15, 2014 2:21 pm

If you enable Phidget library logging to a file, it may give some clues.

-Patrick

cupofnestor
Fresh meat
Posts: 4
Joined: Tue Jul 15, 2014 1:24 pm
Contact:

Re: Startup script on OSX [python]

Postby cupofnestor » Tue Jul 15, 2014 3:27 pm

Thanks for the prompt reply. I've added the following to my script:

Code: Select all

from Phidgets.Phidget import Phidget
Phidget.enableLogging(3,"/Users/PhysicalHumor/exhibit/phidget.log")


When I launch the script via launchctl, there are no launchctl errors, and the Phidget log is empty.
Here is the standard output from my script:

Code: Select all

sound: 0
sound: 1
sound: 2
sound: 3
sound: 4
sound: 5
sound: 6
sound: 7
sound: 8
sound: 9
sound: 10
sound: 11
Opening phidget object....
Opening 326860
Opening 324254
Opening 326331


And here is the output when I launch it directly from the terminal:

Code: Select all

sound: 0
sound: 1
sound: 2
sound: 3
sound: 4
sound: 5
sound: 6
sound: 7
sound: 8
sound: 9
sound: 10
sound: 11
Opening phidget object....
Opening 326860
Opening 324254
Opening 326331
<Phidgets.Devices.InterfaceKit.InterfaceKit instance at 0x109fd75a8>
InterfaceKit 326860 Attached!
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
SensorChanged: sensor 0 on device 0 sound 0
SensorChanged: sensor 1 on device 0 sound 0
SensorChanged: sensor 2 on device 0 sound 1
SensorChanged: sensor 3 on device 0 sound 1
SensorChanged: sensor 4 on device 0 sound 2
SensorChanged: sensor 5 on device 0 sound 2
SensorChanged: sensor 6 on device 0 sound 3
SensorChanged: sensor 7 on device 0 sound 3
<Phidgets.Devices.InterfaceKit.InterfaceKit instance at 0x109fd7ab8>
InterfaceKit 326331 Attached!
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
SensorChanged: sensor 0 on device 2 sound 8
SensorChanged: sensor 1 on device 2 sound 8
SensorChanged: sensor 2 on device 2 sound 9
SensorChanged: sensor 3 on device 2 sound 9
SensorChanged: sensor 4 on device 2 sound 10
SensorChanged: sensor 5 on device 2 sound 10
SensorChanged: sensor 6 on device 2 sound 11
SensorChanged: sensor 7 on device 2 sound 11
<Phidgets.Devices.InterfaceKit.InterfaceKit instance at 0x109fd7908>
InterfaceKit 324254 Attached!
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
INPUT CHANGED
SensorChanged: sensor 0 on device 1 sound 4
SensorChanged: sensor 1 on device 1 sound 4
SensorChanged: sensor 2 on device 1 sound 5
SensorChanged: sensor 3 on device 1 sound 5
SensorChanged: sensor 4 on device 1 sound 6
SensorChanged: sensor 5 on device 1 sound 6
SensorChanged: sensor 6 on device 1 sound 7
SensorChanged: sensor 7 on device 1 sound 7

User avatar
Patrick
Lead Developer
Posts: 3067
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Startup script on OSX [python]

Postby Patrick » Tue Jul 15, 2014 3:29 pm

If the log is empty, this means that enableLogging was not called. Are you sure your python script is able to find the Phidget library code when launched from launchctl?

cupofnestor
Fresh meat
Posts: 4
Joined: Tue Jul 15, 2014 1:24 pm
Contact:

Re: Startup script on OSX [python]

Postby cupofnestor » Tue Jul 15, 2014 4:17 pm

Whether I run it with launchctl or simply with python, it creates the log file and does not write anything.

However, if I "claim" the devices with one instance, and then run the script with launchctl, the error is logged:

Code: Select all

Tue Jul 15 17:14:11 2014,193986560,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cphidget.c(1302)",WARN,"unable to open active device: 1"


I'll add some debug messages to my script, it may be that one of the other deps is causing the problem.

cupofnestor
Fresh meat
Posts: 4
Joined: Tue Jul 15, 2014 1:24 pm
Contact:

Re: Startup script on OSX [python]

Postby cupofnestor » Tue Jul 15, 2014 4:26 pm

Upped the loglevel, here is a level 6 log from a successful start:

Code: Select all

Tue Jul 15 17:22:23 2014,1941185296,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/clog.c(62)",INFO,"Enabling logging"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 41475
"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,53542912,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 43267
"
Tue Jul 15 17:22:23 2014,54079488,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,54616064,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,55152640,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 42755
"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,55689216,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,56225792,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"


And the (unsuccessful) one when initiated by systemctl:

Code: Select all

Tue Jul 15 17:22:23 2014,1941185296,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/clog.c(62)",INFO,"Enabling logging"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 41475
"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,53542912,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 43267
"
Tue Jul 15 17:22:23 2014,54079488,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,54616064,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,55152640,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(675)",INFO,"Attach: 42755
"
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,52920320,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/mac/macusb.c(537)",INFO,"Using Control Endpoint for Host->Device communication."
Tue Jul 15 17:22:23 2014,55689216,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(373)",INFO,"WriteThread running"
Tue Jul 15 17:22:23 2014,56225792,"/Users/buildbot/BuildSystem/working/phidget21/phidget21/cthread.c(253)",INFO,"ReadThread running"


In both cases, pygame and phidgets modules are loaded correctly.

User avatar
Patrick
Lead Developer
Posts: 3067
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Startup script on OSX [python]

Postby Patrick » Wed Jul 16, 2014 9:32 am

It looks to me like the Phidget library is working properly. Are you sure it's possible to play sounds from a launchctl script?

-Patrick

berkinet
Phidget Mastermind
Posts: 153
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Startup script on OSX [python]

Postby berkinet » Fri Jul 18, 2014 11:59 am

If the script is not run setuid the person logged in on the "console." It may not have access to some system resources.


Return to “macOS”

Who is online

Users browsing this forum: No registered users and 2 guests