Thursday, September 24, 2015

Object Oriented Daemon implementation in Python3


1.What is a daemon?

A daemon is program that runs in the background and does some work. It does not need any user interaction to do its work.

Features of a daemon

  • It does not have access to the terminal, i.e. it cannot read or write to the terminal.
  • Only one instance of  it can be created.
  • It works without user interaction.
Example:  sshd is a daemon that services incoming SSH connections.

 2. My python daemon module:

The OO daemon module provided a simple implementation on a daemon which can be used as a base class to create daemon processes. All one needs to do to create a daemon using the daemon module as bellow.
  1. Import the daemon module
  2. Create a child class of the daemon
  3. Override the run method. This is were the business logic for your daemon goes. It should be implemented inside an infinite loop as shown in the example.
  4. Create and instance of the child daemon with daemon name and log directory path as parameters.
  5. Call the startDaemon method  the daemon.  

3. Example: Backup your clip board every 10 seconds.

Clipboard archiver daemon (clipboard_archiver_d.py)

4. Running the daemon

  $ yourdeamon.py [status|restart|stop]

$ ./clipboard_archiver_d2.py
clipcopy: started at 24.09.2015 / 22:22:58
clipcopy: log directory is '/tmp/clipcopy'
clipcopy: going into background........
$ ./clipboard_archiver_d2.py status
clipcopy:DAEMON_RUNNING
$ ./clipboard_archiver_d2.py restart
clipcopy:DAEMON_STOPPED
clipcopy: started at 24.09.2015 / 22:23:15
clipcopy: log directory is '/tmp/clipcopy'
clipcopy: going into background........
$ ./clipboard_archiver_d2.py stop
clipcopy:DAEMON_STOPPED

5. Daemon Module code


6. References

12 comments:

  1. Software solution is the main resource in the world to overcome some big flow of work we should increase research on it research paper proposal service research proposal writing guidelines

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Dynamic sites are not exaggerated by records in the document outline, but against developments that are controlled by the web server ask dissertation plus to write my dissertation, and when the necessities come in and produce the content that is returned to the customer.

    ReplyDelete
  4. Amazing post informative i am php developer i worked different companies and differet type such framework wordpress etc, when i hared about pathon afere that i try to understand basic but i am fail in pathon programming laguage its very complicated language.Online leather Store

    ReplyDelete
  5. Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone. Deadpool Shearling Jacket

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Dynamic locales are not in light of records in the archive structure, however rather on ventures which are controlled by the web server when a UK Dissertation Writing Service request comes in, and which deliver the substance that is returned to the customer.

    ReplyDelete
  8. Despite the fact that Python is a protest arranged dialect without complain or bandy, we have so far mhr writer deliberately maintained a strategic distance from the treatment of question situated programming (OOP) in the past sections of our Python instructional exercise.

    ReplyDelete
  9. Only Professional Writers Can Make This Kind Of Material, Cheers
    !!

    ReplyDelete
  10. I Personally Like Your Post; You Have Shared Good Insights And Experiences. Keep It Up.

    ReplyDelete
  11. I really happy found this website eventually leverage parker leather jacket. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog. Now I saved it to my bookmarks so that I can keep me in touch with you.

    ReplyDelete