Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name Daemon #1

Open
i-make-robots opened this issue Jul 7, 2013 · 4 comments
Open

ImportError: cannot import name Daemon #1

i-make-robots opened this issue Jul 7, 2013 · 4 comments

Comments

@i-make-robots
Copy link

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)
@arpit1997
Copy link

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 😄 😄

@i-make-robots
Copy link
Author

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

@arpit1997
Copy link

Oh my god 📆 This was very long almost 3 years ago. I did not see the date for the issue and your comment, 😺 i was just wandering around 🚶‍♂️ Github, saw this repo so commented on it 🖱️ ⌨️
Well sorry for pinging for this issue. But i suppose i have tried better off my understanding.
LOL 🍭 .

@ravi-score
Copy link

Any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants