Parce que «Ça peut toujours servir»™ et que de toutes façons il y en a déjà des bouts qui sont dans le dépôt et que c'est chiant de git add -f.
Et puis bon, ça fait que 3Mo
This commit is contained in:
parent
29f50c2ed9
commit
3bde363deb
299 changed files with 17466 additions and 0 deletions
47
archive/python-lib/daemon.py
Normal file
47
archive/python-lib/daemon.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# -*- python -*-
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
import sys,os
|
||||
|
||||
def daemonize (stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
|
||||
'''This forks the current process into a daemon.
|
||||
The stdin, stdout, and stderr arguments are file names that
|
||||
will be opened and be used to replace the standard file descriptors
|
||||
in sys.stdin, sys.stdout, and sys.stderr.
|
||||
These arguments are optional and default to /dev/null.
|
||||
Note that stderr is opened unbuffered, so
|
||||
if it shares a file with stdout then interleaved output
|
||||
may not appear in the order that you expect.
|
||||
'''
|
||||
# Do first fork.
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0) # Exit first parent.
|
||||
except OSError, e:
|
||||
sys.stderr.write ("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror) )
|
||||
sys.exit(1)
|
||||
|
||||
# Decouple from parent environment.
|
||||
os.chdir("/")
|
||||
os.umask(022)
|
||||
os.setsid()
|
||||
|
||||
# Do second fork.
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0) # Exit second parent.
|
||||
except OSError, e:
|
||||
sys.stderr.write ("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror) )
|
||||
sys.exit(1)
|
||||
|
||||
# Now I am a daemon!
|
||||
|
||||
# Redirect standard file descriptors.
|
||||
si = file(stdin, 'r')
|
||||
so = file(stdout, 'a+')
|
||||
se = file(stderr, 'a+', 0)
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
Loading…
Add table
Add a link
Reference in a new issue