def flopen(*args, **kwargs):
    '''
    Shortcut for fopen with lock and context manager.
    '''
    filename, args = args[0], args[1:]
    writing = 'wa'
    with fopen(filename, *args, **kwargs) as f_handle:
        try:
            if is_fcntl_available(check_sunos=True):
                lock_type = fcntl.LOCK_SH
                if args and any([write in args[0] for write in writing]):
                    lock_type = fcntl.LOCK_EX
                fcntl.flock(f_handle.fileno(), lock_type)
            yield f_handle
        finally:
            if is_fcntl_available(check_sunos=True):
                fcntl.flock(f_handle.fileno(), fcntl.LOCK_UN)
Shortcut for fopen with lock and context manager.