示例#1
0
def start_daemon(pidfile, process, stdout=None, stderr=None, **kwargs):
    if pidfile:
        pidfile = PIDLockFile(pidfile)
        try:
            pidfile.acquire(timeout=1.0)
            pidfile.release()
        except LockFailed:
            raise
    else:
        pidfile = None

    stdout = stdout or sys.stdout
    stderr = stderr or sys.stderr
    with DaemonContext(pidfile=pidfile, stdout=stdout, stderr=stderr, **kwargs):
        process.start()
示例#2
0
文件: pet.py 项目: Gateswong/GatesPet
    # TaskManager instance.
    tm = TaskManager(mongo, max_tasks=max_tasks, scan_interval=scan_interval)
    return tm

lock = PIDLockFile('pet.pid')

if lock.is_locked() and not lock.i_am_locking():
    if not psutil.pid_exists(lock.read_pid()):
        print 'The pidlock is hold by a void process. Breaking it.'
        lock.break_lock()
    else:
        print 'Another process is holding pidlock. Exit.'
        exit()

print 'Acquiring pidlock.'
lock.acquire(timeout=5)

# TODO Load config.
mongo = MongoDataAdapter.create_adapter('GatesPet')
max_tasks = 50
scan_interval = 10
process_interval = 120

tm = create_task_manager(mongo, max_tasks, scan_interval)

# Fix tasks that previous instance did not proceed.
mongo.fix_tasks()

# Main loop
tm.start()