def acquire_for(pid_dir, num_available=1, kill_signal=None):

    my_pid, my_cmd, pid_file = get_info(pid_dir)

    # Check if there is a pid file corresponding to this name
    if not os.path.exists(pid_dir):
        os.mkdir(pid_dir)
        os.chmod(pid_dir, 0o777)

    pids = set()
    pid_cmds = {}
    if os.path.exists(pid_file):
        # There is such a file - read the pid and look up its process name
        pids.update(filter(None, map(str.strip, open(pid_file))))
        pid_cmds = dict((pid, getpcmd(pid)) for pid in pids)
        matching_pids = list(filter(lambda pid: pid_cmds[pid] == my_cmd, pids))

        if kill_signal is not None:
            for pid in map(int, matching_pids):
                os.kill(pid, kill_signal)
        elif len(matching_pids) >= num_available:
            # We are already running under a different pid
            print('Pid(s)', ', '.join(matching_pids), 'already running')
            return False
        else:
            # The pid belongs to something else, we could
            pass
    pid_cmds[str(my_pid)] = my_cmd

    # Write pids
    pids.add(str(my_pid))
    with open(pid_file, 'w') as f:
        f.writelines('%s\n' % (pid, ) for pid in filter(pid_cmds.__getitem__, pids))

    # Make the file writable by all
    if os.name == 'nt':
        pass
    else:
        s = os.stat(pid_file)
        if os.getuid() == s.st_uid:
            os.chmod(pid_file, s.st_mode | 0o777)

    return True
Set a marquee string option.
dataset/ETHPy150Open spotify/luigi/luigi/lock.py/acquire_for--crossover with--dataset/ETHPy150Open disqus/playa/playa/lib/vlc.py/MediaPlayer.video_set_marquee_string