Question

I have written a python script that queries cx_Oracle and processes the results. Now I'm ready to schedule it on my mac OS10.8 using launchd.

As you may know, cx_Oracle on this mac OS requires unweildy solutions to control the bitness of the python that runs the .py script. These solutions range from lipoing your python (on the install or in the virtual environment) to specifying the bitness manually when you run the script, e.g. "arch -i386 /usr/bin/python2.7 scriptname.py".

I have read through the plist documentation, and as far as I can tell, you can't specify bitness as part of the plist configuration. Perhaps you could in the Info.plist file that applies to python, but then it would apply to every .py script you schedule. In which case you might as well only have a 32 or 64 bit python install.

Understanding that my goal is schedule scripts and specify per script the bitness of the python that runs it, what would you recommend? Is there something easy I'm overlooking? Your advice is greatly appreciated!

Was it helpful?

Solution

~/library/LaunchAgents/local.arch.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.arch</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/arch</string>
        <string>-i386</string>
        <string>/usr/bin/python2.7</string>
        <string>/volumes/ramdisk/arch.py</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
</dict>
</plist>

/volumes/ramdisk/arch.py:

import sys

with open('/volumes/ramdisk/python.arch.log', 'a') as f:
    f.write('sys.maxsize = %s\n' % sys.maxsize)

In terminal:

$ launchctl load ~/library/LaunchAgents/local.arch.plist
$ launchctl start local.arch
$ # arch -i386, 32-bit
$ cat /volumes/ramdisk/python.arch.log
sys.maxsize = 2147483647
$ # no arch, 64-bit
$ /usr/bin/python2.7 -c 'import sys; print(sys.maxsize)'
9223372036854775807
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top