[Tutor] using Python with time

lumbricus@gmx.net lumbricus@gmx.net
Tue, 24 Apr 2001 21:56:10 +0200


--bp/iNruPH9dso1Pn
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On Mon, Apr 23, 2001 at 09:09:27PM -0500, rob@jam.rr.com wrote:
> I'd like to write a Python app that I can run "in the background" in
                                                ^^^^^^^^^^^^^^^^^^^
						you are talking about
						daemons !
						see attchmnt 
						(posting from c.l.py)
						
> both Windows and Linux/BSD/*nix, although it's hardly mission-critical
> that this be cross-platform. What I'd like it to do is notify me at
> certain times of day (say, at 10:32 a.m. and 3:40 p.m.) or after a given
> interval of time (say, every XYZ minutes from the moment the app is
> activated).
> 
does win know about syslog ?

> My practical aim for it is to have a way to remind myself to practice
> mindfulness every so often during the day, but I'm also curious how to
> handle the timing part of the code. If anyone could recommend where I
> can look on the timing part, I'll credit helpful folk when I post the
> code to Useless Python!</bribe>
> 
> Rob
> -- 
> 
> Useless Python!
> If your Python is this useless, we need you.
> http://www.lowerstandard.com/python/pythonsource.html
> 

HTH Jö!

--
I just remembered something about a TOAD!

--bp/iNruPH9dso1Pn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="daemon.py"

#  Daemon Module - basic facilities for becoming a daemon process
#
#  Combines ideas from Steinar Knutsens daemonize.py and
#  Jeff Kunces demonize.py

"""Facilities for Creating Python Daemons"""

import os
import time
import sys

class NullDevice:
    def write(self, s):
        pass

def daemonize():
    if (not os.fork()):
        # get our own session and fixup std[in,out,err]
        os.setsid()
	os.chdir("/")
	os.umask(000)
        sys.stdin.close()
        sys.stdout = NullDevice()
        sys.stderr = NullDevice()
        if (not os.fork()):
            # hang around till adopted by init
            ppid = os.getppid()
            while (ppid != 1):
                time.sleep(0.5)
                ppid = os.getppid()
        else:
            # time for child to die
            os._exit(0)
    else:
        # wait for child to die and then bail
        os.wait()
        sys.exit()



--bp/iNruPH9dso1Pn--