我编写了以下程序以将我的程序作为守护程序运行,但它没有运行;当我从 python 调试器运行程序时,它可以工作。
我正在使用 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()
而且我还使用以下命令从终端运行程序。
launchctl load /Library/LaunchDaemons/com.bobbob.osx.test.plist
这不会导致任何错误。