Beispiel #1
0
pidfn = '/tmp/test_daemonize.pid'


def write_file(fn, cont):
    try:
        with open(fn, 'w') as f:
            f.write(cont)
    except Exception as e:
        print repr(e) + ' while write_file:' + fn
        raise


def run():
    try:
        code, out, err = proc.shell_script('/usr/sbin/lsof -p ' + str(os.getpid()))
    except Exception as e:
        print repr(e)
    write_file(foo_fn, repr(out))


if __name__ == '__main__':

    fd = open(bar_fn, 'w')
    op = sys.argv[1]
    # daemonize.daemonize_cli neede sys.argv[1] to decide what to do.
    sys.argv[1] = 'start'
    if op == 'close':
        daemonize.daemonize_cli(run, pidfn, close_fds=True)
    else:
        daemonize.daemonize_cli(run, pidfn, close_fds=False)
Beispiel #2
0
import time

import daemonize

fn = '/tmp/bar'
pidfn = '/tmp/test_daemonize.pid'


def write_file(fn, cont):
    with open(fn, 'w') as f:
        f.write(cont)


def run():

    write_file(fn, 'bar-before')

    time.sleep(1)

    write_file(fn, 'bar-after')


daemonize.daemonize_cli(run, pidfn)
import time

import daemonize

fn = '/tmp/foo'
pidfn = '/tmp/test_daemonize.pid'


def write_file(fn, cont):
    try:
        with open(fn, 'w') as f:
            f.write(cont)
    except Exception as e:
        print repr(e) + ' while write_file:' + fn
        raise


def run():

    write_file(fn, 'foo-before')

    time.sleep(1)

    write_file(fn, 'foo-after')


daemonize.daemonize_cli(run, pidfn)