python-daemon icon indicating copy to clipboard operation
python-daemon copied to clipboard

ImportError: cannot import name Daemon

Open i-make-robots opened this issue 12 years ago • 4 comments

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)

i-make-robots avatar Jul 07 '13 23:07 i-make-robots

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__.py file into daemon.py directory.
  • 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:

arpit1997 avatar Oct 28 '16 17:10 arpit1997

I don't even remember what this was about. It's been too long.

i-make-robots avatar Oct 28 '16 18:10 i-make-robots

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: .

arpit1997 avatar Oct 28 '16 18:10 arpit1997

Any workaround?

ravi-score avatar Jul 27 '18 14:07 ravi-score