ImportError: cannot import name Daemon
Code as follows:
!/usr/bin/python
-- coding: utf-8 --
python daemon to connect PHP and Arduino
[email protected] 2013
from daemon import Daemon import logging import lockfile import time import sys
config
PIDFILE = '/var/run/ardaemon.pid' LOGFILE = '/var/log/ardaemon.log'
run the thing
logging.basicConfig(filename=LOGFILE,level=logging.DEBUG)
class YourDaemon(Daemon): def run(self): while True: logging.debug('this is a test') time.sleep(5)
if name == "main": daemon = YourDaemon(PIDFILE)
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
try:
daemon.start()
except:
pass
elif 'stop' == sys.argv[1]:
print "Stopping ..."
daemon.stop()
elif 'restart' == sys.argv[1]:
print "Restaring ..."
daemon.restart()
elif 'status' == sys.argv[1]:
try:
pf = file(PIDFILE,'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
pid = None
except SystemExit:
pid = None
if pid:
print 'YourDaemon is running as pid %s' % pid
else:
print 'Your Daemon is not running.'
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart|status" % sys.argv[0]
sys.exit(2)
There could be many possible reasons for this error
from daemon import Daemon
import logging
import lockfile
import time
import sys
You may try one of these:
- add an empty
__init__.pyfile intodaemon.pydirectory. - Try to add it in pythonpath.
- Last option that i have n mind is that you try running it in virtualenv.
Hope this helps :smile: :smile:
I don't even remember what this was about. It's been too long.
Oh my god :calendar: This was very long almost 3 years ago. I did not see the date for the issue and your comment, :smiley_cat: i was just wandering around :walking_man: Github, saw this repo so commented on it :computer_mouse: :keyboard: Well sorry for pinging for this issue. But i suppose i have tried better off my understanding. LOL :lollipop: .
Any workaround?