I write the following program to run my program as a daemon but it is not getting run; when i run the program from python debugger it works.
I am using Mac os x.
/User/Library/LaunchDaemons/com.bobbob.osx.test.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.bobbob.osx.test</string>
<key>Program</key>
<string>/Users/vivekbhintade/Desktop/test.py</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
/Users/vivekbhintade/Desktop/test.py
:
import urllib2
from datetime import datetime
import smtplib
from smtplib import SMTPException
import threading
def checkerror():
#my code which works fine individually, which sends mail after 5 seconds to recipients.
checkerror()
And also i run the program from terminal with following command.
launchctl load /Library/LaunchDaemons/com.bobbob.osx.test.plist
This does not result in any errors.
You have almost certainly realised this in the intervening 3 months since posting, but there seems to be some confusion here between Launch Daemons and Launch Agents which I though it would be worth clearing up - especially since Agents are often referred to as Daemons.
Paraphrasing the Apple Developer library:
/Library/LaunchDaemons/
. /Users/username/Library/LaunchAgents/
. Your program will not run as it's located in /User/Library
- it needs to go into one or another of the paths mentioned above, depending on how you plan to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With